Skip to content Skip to sidebar Skip to footer

Submit Form With Apps Script

I'm having the problem described in Google Script - Sidebar button keeps opening a new tab. I initially was using: But ran into a p

Solution 1:

Issue:

forms is not a valid css selector or a node name. So, preventDefault() is never attached to the form submit event on load.

Answer :

Replace

document.querySelectorAll('forms');

with

document.querySelectorAll('form');

References:

Solution 2:

Probably you receive the "unsafe navigation" warning because of additional unspecified arguments passed from withSuccessHandler to google.script.host.close. When providing success handlers, if they are not your own function (i.e. you know exactly what arguments they take and use), you are best off accessing them in an anonymous function:

...
google.script.run
  .withSuccessHandler(() => google.script.host.close())
  .withFailureHandler(unhandledServersideException => console.log(unhandledServersideException))
  .foo();
...

If you don't want to use arrow syntax in the HTML files, that would be

withSuccessHandler(function() { google.script.host.close(); })

In this manner you ensure that whatever the output of foo is, it is not passed to google.script.host.close

Post a Comment for "Submit Form With Apps Script"