The description is simple: I have three checkboxes and the third one must select all the others when selected (and deselect them as well, once it's unchecked). All this must be in a grid, I can't use html or any other language but Google Apps Script.
This is probably a simple task for you, but I'm struggling a lot, both with javascript and english. Anyway here's the code:
function checkboxes() {
var range = SpreadsheetApp.getActiveSpreadsheet();
var sheet = range.getSheetId();
var myapp = UiApp.createApplication().setTitle('Title').setWidth(1000).setHeight(100);
var mygrid = myapp.createGrid(3, 3).setCellPadding(5).setCellSpacing(5);
//One
mygrid.setWidget(0, 0, myapp.createLabel('One').setId('One'));
mygrid.setWidget(0, 1, myapp.createCheckBox().setName('One'));
//Two
mygrid.setWidget(1, 0, myapp.createLabel('Two').setId('Two'));
mygrid.setWidget(1, 1, myapp.createCheckBox().setName('Two'));
var handler1 = myapp.createClientHandler().forTargets(myapp.getElementById('One')).setValue(true).forTargets(myapp.getElementById('Two')).setValue(true);
//Last
mygrid.setWidget(2, 0, myapp.createLabel('Last').setId('Last'));
mygrid.setWidget(2, 1, myapp.createCheckBox().setName('Last').OnClickHandler(handler1));
//...
}
Today I finally had the time to see your code, thanks for your support.
Like you said in your comment, I don't need the image at all, so I'm trying to take it out from the function mygui, let's see if I can do it:
I have just cancelled line nr 2, 3 and 8 then I truncked line nr 9 and 10. That's enough for un unexpected mistake, standing to the error message.
Here is a possible workaround with client handler :(tested)
I personally find it easier and more clear to use variables for widget creation instead of having to get them by id... a few lines of code to write but easier to read ;-)
EDIT : following Henrique's comment (very clever !! thanks) here is a 'full checkBoxes' version that works just fine ;-)
Last time I tried it was not possible to use ClientHandlers validations with with checkboxes. So you have to stick with serverhandlers, which are slower, so you might need to add a little infinity progress gif so the user knows something is being done.
Here's an example of the solution I use: