I am a beginner in app scripting and I have a question.
How can I disable a button when I press another button.
I tried many different ways, but I can't get it to work.
Can you help me?
My code is large. Should I paste it here?
in UiApp you can use clientHandler to do that very easily...
example code goes like this :
function doGet() {
var app = UiApp.createApplication();
var btn1 = app.createButton('button1');
var btn2 = app.createButton('button2');
var clientHandler = app.createClientHandler().forTargets(btn1).setEnabled(false);
btn2.addClickHandler(clientHandler);
return app.add(btn1).add(btn2);
}
Note : the comments above are right... your question was indeed too vague.
Yes, you will need to post some relevant code before anyone will be able to help you.
Broadly speaking, a good logical approach to achieving what you want to do, is to use the event that occurs, or state that is invoked by clicking the first button, to run script that will disable your second button.
This can be done many different ways. Client Side, Server Side.. it all really depends on context as to which is right for your situation.
Related
I have a doubt regarding how can I interact with the user at a google spreadsheet.
The idea is to show a menu, with some options, let the user select one and then process some spreadsheet data according to it. This should be done within the srpeadsheet.
The problem is, I'm not sure what is the best way to accomplish this.
At a firs instance, I though at HTML service, but I'm not sure the communication to the server side works from a spreadsheet.
I have this code, which in fact, acess to the server side, but It's pretty simple
function showHtml(htmlText){
htmlText=htmlText+'<input type="button" value="Close" onclick="google.script.host.close()" />';
var html = HtmlService.createHtmlOutput(htmlText);
thisSpr.show(html);
}
Any ideas? Just want to know which should be the best way and one or two tips on how to.
Check out Class Menu, maybe you can get what you need.
I am new to the world of Google's Apps Script, and I am trying to create a basic UI for my end user to query data (stored in google spreadsheets) and display the data in a formatted / user friendly way.
Since I want to start off simple and add in components as I learn Apps Script I decided to create a basic form that will allow me to enter text in a text box, then assign that value to a label (what I thought would be a simple exercise in creating basic form components, and retrieving / assigning values).
Unfortunately the stumbling block I ran into is that there is no getText() or TextBox.getValue() function. I tried searching through online forums / google etc to find out the way around this, but nothing I try seems to work (previous searched led me totry and work this out in an event handler).
My question is this. If I have a textBox ('textBox1') and a button ('button1') and a label ('label1'). How to I get my web app to assign the value I enter in textBox1 to label1 when I click button1?
I realize this is probably the most basic of questions, and I know it has been asked before....but no matter how hard I dig through these old posts I can't seem to figure what should be an easy bit of code out.
Thanks in advance.
Suppose you have code that looks like this:
var textbox = app.createTextBox().setName("textboxName");
var buttonHandler = app.createServerHandler("updateLabelText").addCallbackElement(textbox);
var button = app.createButton("Click me").addClickHandler(buttonHandler);
var label = app.createLabel().setId("label");
Then in your function:
function updateLabelText(e) {
var app = UiApp.getActiveApplication();
app.getElementById("label").setText(e.parameter.textboxName);
return app;
}
So the things to note:
The button handler is given the name of a function that you define somewhere else in your code.
The button handler also must be given a "callback element". This is required if you want to read the value of that element in your function. You can add a panel as a callback element and anything that's on that panel will be added to the callback.
Values of callback elements are passed back through e.parameter. The property name is the name of the element. Example: e.parameter.textboxName.
The label needs an ID so that you can reference it from your other function.
Using UiApp to collect data from a form, but I have users double clicking the submit button. This runs doPost twice. Granted, they have to click mighty fast to get it to actually post twice, but it happens.
My questions is: has anyone had experience in disabling the submit button, say with an onMouseUp? Is there a better way to do this? I've been told to be wary of adding multiple onClick handlers to buttons, as it can be unstable. Any stable solutions to this?
I have to use a submit button as there is a file upload in the form.
I've faced this problem and ever since Google introduced ClientHandlers, there is a way out.
Just add a client handler to your submit button disabling it (and remember to enable it when you are done with the server handler function or doPost)
var plswait = app.createClientHandler().forEventSource().setEnabled(false).setText('Please wait...');
var btnSubmit = app.createSubmit().addMouseDownHandler(plswait);
is my favourite.
The first answer didn't work for me because the MouseDown handler didn't let the ServerHandler run. But it gave me the right direction. I just added the Client handler to disable the button before I added the Server Handler...and that seemed to work to prevent the double click. Like this:
var submitButton = myapp.createButton("Submit");
var myServerHandler = myapp.createServerClickHandler("myServerHandler");
var pleaseWait = myapp.createClientHandler().forEventSource().setEnabled(false).setText('submitting...');
submitButton.addClickHandler(pleaseWait);
submitButton.addClickHandler(myServerHandler);
I had the same problem, but to work around it I created a second "false" button that becomes visible when the submit button is clicked, at the same time the "real" submit button visibility is set to false. Here's the basic code:
var button = app.createSubmitButton('Submit').setId("button")
.setEnabled(false)
var falseButton = app.createButton('Submit').setId("falseButton")
.setEnabled(false)
.setVisible(false);
var handler = app.createClientHandler()
.forTargets(button).setVisible(false)
.forTargets(falseButton).setVisible(true);
button.addClickHandler(handler);
panel.add(app.createHorizontalPanel().add(button).add(falseButton);
Hi and Good day to all,
Google App Script can be used in so many ways. I know cause I have tried some of them but Iam not an expert so, the situation is.
I have created an Spreadsheet
create a form using the new UI Building that comes with the script editor.
named:gtest01
UI compose of:
label, id=label_caption
button 1, id=button_hide, event-onmouseclick=hide_label
button 2, id=button_show, event-onmouseclick=show_label
button 3, id=button_message, event-onmouseclick=message_me
now, the code is:
/* This is so when I want to just deploy it as a [webapp] using the
script editor -> Publish Deploy as Web App
*/
function doGet(e) {
var app = UiApp.createApplication().setTitle("Sheet Application");
app.add(app.loadComponent("gtest01"));
Logger.log("Application UI Loaded");
return app;
}
function message_me(e) {
Browser.msgBox("my message");
}
function hide_label(e) {
var app = UiApp.getActiveApplication();
label =app.getElementById("label_caption");
label.setVisible(false);
}
function show_label(e) {
var app = UiApp.getActiveApplication();
label =app.getElementById("label_caption");
label.setVisible(true);
}
// this code is for when the spreadsheet is shared so they can access the form
function showform_() {
var app = UiApp.createApplication();
app.add(app.loadComponent("gtest01"));
SpreadsheetApp.getActiveSpreadsheet().show(app);
}
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [];
menuEntries.push({name: "Show Form", functionName: "showform_"});
ss.addMenu("e-Test", menuEntries);
}
First scenario is that when spreadsheet is shared
when menu is clicked the form will load - thats good
when show and hide button nothing happens - why and how can i fixed
this?
when message button is click - message will show but the form will
close, how can I display a message without closing the form?
Second scenario is that when publish as Webapp.
When Developer Link is Access the UI is always updated - ok
When URL Link is Access the UI is always updated its like it is
cache, how can I fixed this?
on dev link: when show and hide button nothing happens - why and how
can i fixed this?
on dev link: when message button is click - will generate an error,
how can I display an alert message on WebApp
Please help I have search and tried the sample codes and answer in the forum am missing something.
Thanks
Nick Ace
First scenario
when show and hide button nothing happens - why and how can i fixed this?
In your functions, use return app at the end. Unless you return the app object, the UI doesn't get updated.
how can I display a message without closing the form? - Try
SpreadsheetApp.getActiveSpreadsheet().toast()
2nd scenario
When URL Link is Access the UI is always updated its like it is cache, how can I fixed this? - Save your most recent code as a version
on dev link: when show and hide button nothing happens - Again return app will take care of this
on dev link: when message button is click... - Browser.msgBox is not supported in a web app.
When Using UI it is generally a good idea to make everything happen inside this Ui, so try to avoid showing messages with Toast( as they are not supported in web apps anyway).
Since you are using the GUI it should be quite easy to use a label with your message that is initially invisible and to make it visible in an handler routine.
Note that this kind of handler can be a client handler as well unless you need to do something else from this action.
As for the other points of you question, our (very fast) friend Srik has already answered thoroughly ;-)
Hi I would be so grateful if anyone could shed some light on this, Basically I have a iphone app built using jqtouch and phonegap which has a list of standard checkboxes and when they are selected a strikethrough effect will be applied, easy enough (kind of like a simple checklist) this is all dealt with on the client side and nothing will be getting sent anywhere.
However, when the user closes the app the checkboxes revert to their original sate i.e all unchecked and i would like them remain as the user left them. I guess local storage would be the way to do this, however, i have gave it a go and i am getting a bit confused.
Any help would be great, and thank you in advance.
kyle
Here you go:
$(document).ready(function() {
$('form')
.delegate(':checkbox','change',function() {
var $this = $(this);
localStorage.setItem('checkbox' + $this.index('form :checkbox'),$this.attr('checked').toString());
})
.find(':checkbox')
.each(function(index) {
if(localStorage.getItem('checkbox' + index) === 'true') $(this).attr('checked',true);
});
});
Took some time to write it correctly myself but I think it's worth it. The default state handling is up to you (like when a checkbox is already checked with HTML).