Reputation: 11120
I am trying to use the HTMLService to manage simple forms. This is an archetypal HTML form (NATIVE
option is for portability):
form.gs
:
function htmlTest (){
var html = HtmlService.createHtmlOutputFromFile('form');
html.setSandboxMode(HtmlService.SandboxMode.NATIVE);
SpreadsheetApp.getUi().showModalDialog(html, "Sample Form");
}
function cBack (el1, el2){
Browser.msgBox('Data sent');
Logger.log(el1);
Logger.log(el2);
}
form.html
:
Enter field 1: <input name="name1" id='input1'>
<br>
Enter field 2: <input name="name2" id='input2'>
<br>
<input type='button' value='Submit' onclick='fParser()'>
<script>
function fParser() {
var el1=document.getElementById('input1').value;
console.log(el1);
var el2=document.getElementById('input2').value;
console.log(el2);
google.script.run.cBack(el1, el2);
google.script.host.close();
}
</script>
How can I debug efficiently a callback triggered from served HTML?
What to do when a callback does not start?
I see that sometimes it is just a matter of closing and reopening the document to fix the problem: is there a more efficient way to reload the code?
Upvotes: 0
Views: 446
Reputation: 3778
I've found it easier to debug everything in the HTML page, to get back the variables use withSuccessHandler. This way you can keep editing the .gs and on the click of a button get the new results on the console.
Eg.
google.script.run.withSuccessHandler(debugging).cBack(el1, el2);
google.script.run.withSuccessHandler(debugging).anotherCallBacl(el);
function debbugging( logs ){
console.log( logs );
}
and the .gs:
function cBack (el1, el2){
Browser.msgBox('Data sent');
return "el1 : " + el1 + " - el2: " + el2;
}
Upvotes: 2