Label text in event handler
In this example, I have shown a workaround for getting the label text in event parameter. This workaround can be very useful in some situations.
Reference:
http://code.google.com/googleapps/appsscript/class_label.html
http://code.google.com/googleapps/appsscript/class_button.html
http://code.google.com/googleapps/appsscript/class_serverclickhandler.html
Example demo:
To try the demo, click on submit button
Example Code:
function doGet() {
var app = UiApp.createApplication();
//Create a penel which will hold all the elements
var panel = app.createVerticalPanel();
//Create a label, also set a tag to that label. Tag value must be same as the label text
var label = app.createLabel('This is my Label').setId('myLabel').setTag('This is my Label');
var button = app.createButton('Submit');
//Create a invisible label which will be visible after submit,
//and hold the tag value/label text
var labelInfo = app.createLabel().setVisible(false).setId('labelInfo');
//Create a handler for the button
var handler = app.createServerClickHandler('showDates');
//add the panel as a callback element
handler.addCallbackElement(panel);
button.addClickHandler(handler);
//Add all the lements to the panel
panel.add(label).add(button).add(labelInfo);
//Add the panel to the application
app.add(panel);
return app;
}
//this function will show the dates
function showDates(e){
//get the active aplication
var app = UiApp.getActiveApplication();
//get the tag value which is equal to the label text
var labelText = e.parameter.myLabel_tag;
app.getElementById('labelInfo').setText(labelText).setVisible(true);
return app;
}