Lyu Hiroyama
Lyu Hiroyama

Reputation: 97

Google Apps Script alert showing twice when called from HTML dialog

I've got three files that does one simple thing:

  1. User via custom menu opens a modal dialog
  2. User clicks button on modal dialog
  3. button click calls a function that displays a simple alert

That's it. But...the alert gets displayed TWICE. Here is the code:

custom-menu.gs

function onOpen() {
  SpreadsheetApp.getUi().createMenu('custom menu')
      .addItem('button 1','someFunction')
      .addToUi();
}

gas-file.gs

function someFunction() {
  const htmlOutput = HtmlService.createHtmlOutputFromFile("html-file");
  SpreadsheetApp.getUi().showModalDialog(htmlOutput, "Some Title");
}

function someFunc1() {
  SpreadsheetApp.getUi().alert("someFunc1() has been called.")
}

html-file.html

<!DOCTYPE html>
<html>
  <body>
    <button type="button" onclick="submit()">Submit</button>
    <script>

      function submit() {
        google.script.run.someFunc1();
      }      

    </script>
  </body>
</html>

I'm completely baffled. Any help would be greatly appreciated. Thank you in advance!

Upvotes: 0

Views: 51

Answers (0)

Related Questions