What is the easiest way to get some kind of toggle switch for Google HtmlService?
Google UiApp
used to be able to create a simple ToggleButton like the following:
var toggleButton = app.createToggleButton('ON', 'Off').setId('MySwitch');
But UiApp has been deprecated. "Please use HtmlService instead"
I've tried
- https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_radio_value
- https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_checkbox_value
But found I cannot make them a two-stage item. Then I tried
and was able to get the HTML part working, but moving it to Google HtmlService, I cannot make it work no matter what.
Can someone give me a working Google HtmlService example that contains a two-stage item that I can use to control my output please.
UPDATE:
Thanks a lot @MetaMan for your excellent example, I tried hard to come up with the smallest example, but I'll never be able to get the level of your code, so compact and elegant!
Just one thing, I haven't been able to make it work yet. I'm getting ReferenceError: gobj is not defined
.
I then changed them into plain text, as
But got Execution completed
without seeing the dialog.
How can I make it works?
UPDATE2:
Ops, dialog showed up after a while. Thanks @MetaMan, I'll ask the following in a separated question --
One more thing, @MetaMan, In the HTML demo code that I provided, I was able to make use of form.myButton.value
, but the problem is when I try to use that to update my label from within Google App Code function, just as what the HTML demo code is doning, it always fails and I don't know why. Do you have a quick answer for that, or you'd rather me asking in a separated question?
thx