Tengo una barra lateral personalizada generada a través de Apps Script en una hoja de Google.
El HTML de la barra lateral personalizada contiene un formulario y un conjunto de campos con 5 elementos de entrada de radio, todos con eventos de cambio:
google.script.run.viewOptionsFormRadioChange(this);Aquí está el formulario HTML completo:
<form id="viewOptionsForm"> <fieldset class="viewOptionsFieldset"> <input type="radio" id="all" name="viewOptionsRadio" value="All" checked="checked" onchange='google.script.run.viewOptionsFormRadioChange(this);' > <label for="all">All</label><br> <input type="radio" id="firstImport" name="viewOptionsRadio" value="First Import" onchange='google.script.run.viewOptionsFormRadioChange(this);'> <label for="firstImport">First Import</label><br> <input type="radio" id="secondImport" name="viewOptionsRadio" value="Second Import" onchange='google.script.run.viewOptionsFormRadioChange(this);'> <label for="secondImport">Second Import</label><br> <input type="radio" id="compositionLinking" name="viewOptionsRadio" value="Composition Linking" onchange='google.script.run.viewOptionsFormRadioChange(this);'> <label for="compositionLinking">Composition Linking</label><br> <input type="radio" id="underTheHood" name="viewOptionsRadio" value="Under the Hood" onchange='google.script.run.viewOptionsFormRadioChange(this);'> <label for="underTheHood">Under the Hood</label> </fieldset> </form>Luego tengo una función "viewOptionsFormRadioChange":
function viewOptionsFormRadioChange(checkbox) { if(checkbox.checked == true){ if(checkbox.attr('id') == "underTheHood") { SpreadsheetApp.getActive().toast("underTheHood Selected", "Title", 15); } } }Estoy tratando de obtenerlo para que aparezca la notificación de brindis cuando selecciono el botón de opción Bajo el capó, sin embargo, el parámetro del elemento "este" no parece aparecer como variable de parámetro: casilla de verificación ya que lo anterior no funciona.
¿Alguna idea de dónde me estoy equivocando?
gracias de cualquier manera
Creo que en su secuencia de comandos, ¿qué tal modificar this a this.value o this.id ? Parece que en este caso, this no se puede analizar. Entonces, cuando se modifica su secuencia de comandos, ¿qué tal la siguiente modificación?
En esta modificación, se modifica su HTML.
<form id="viewOptionsForm"> <fieldset class="viewOptionsFieldset"> <input type="radio" id="all" name="viewOptionsRadio" value="All" checked="checked" onchange='google.script.run.viewOptionsFormRadioChange(this.value);' > <label for="all">All</label><br> <input type="radio" id="firstImport" name="viewOptionsRadio" value="First Import" onchange='google.script.run.viewOptionsFormRadioChange(this.value);'> <label for="firstImport">First Import</label><br> <input type="radio" id="secondImport" name="viewOptionsRadio" value="Second Import" onchange='google.script.run.viewOptionsFormRadioChange(this.value);'> <label for="secondImport">Second Import</label><br> <input type="radio" id="compositionLinking" name="viewOptionsRadio" value="Composition Linking" onchange='google.script.run.viewOptionsFormRadioChange(this.value);'> <label for="compositionLinking">Composition Linking</label><br> <input type="radio" id="underTheHood" name="viewOptionsRadio" value="Under the Hood" onchange='google.script.run.viewOptionsFormRadioChange(this.value);'> <label for="underTheHood">Under the Hood</label> </fieldset> </form> Pero, en este caso, el valor devuelto es el valor de cadena como First Import , Second Import ,,,. Por lo tanto, es posible que deba modificar su Google Apps Script de la siguiente manera.
function viewOptionsFormRadioChange(checkbox) { if(checkbox == "Under the Hood") { SpreadsheetApp.getActive().toast("underTheHood Selected", "Title", 15); } } Con esta modificación, cuando marca "Bajo el capó", se ejecuta la toast() .
id , modifique this.value a this.id . Por esto, puede usar el valor de ID en su etiqueta HTML. Es como if(checkbox == "underTheHood") {,,,} en lugar de if(checkbox == "Under the Hood") {,,,} .