【问题标题】:Make submit button close dialog and return focus to spreadsheet google app script使提交按钮关闭对话框并将焦点返回到电子表格谷歌应用程序脚本
【发布时间】:2019-06-28 11:29:41
【问题描述】:

当我单击提交时,焦点返回电子表格并加载数据,但对话框没有关闭。我使用了google.script.host.close(),但这不会将焦点传递回电子表格。

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
<form >
  Select Client:
  <div>
  <select id="optionList" name="client">   
  </select>
  </div> 
   Select Action:
  <div>
  <select id="actionList" name="action">   
  </select>
  </div> 
  Username:
  <input type="text" name="username"> <br />
  Password:
  <input type="password" name="password"> <br />
  <input type="button" value="OK" onclick="google.script.run.callNumbers(this.parentNode);google.script.host.editor.focus();" />
</form>
  </body>

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<script>
    // The code in this function runs when the page is loaded.
    $(function () {
        google.script.run.withSuccessHandler(buildOptionList)
            .getClients();
            google.script.run.withSuccessHandler(buildActionList)
            .getActions();
    });

    function buildOptionList(clients) {
        var list = $('#optionList');
        list.empty();
        for (var i = 0; i < clients.length; i++) {
            list.append(new Option(clients[i]));
        }
    }

     function buildActionList(actions) {
        var list = $('#actionList');
        list.empty();
        for (var i = 0; i < actions.length; i++) {
            list.append(new Option(actions[i]));
        }
    }
</script>


</html>
    function html(){
       var html = HtmlService.createHtmlOutputFromFile('load');
       SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
       .showModalDialog(html, 'Input API Creddentials');
    }

我想在关闭对话框后让焦点回到电子表格。我曾尝试在沙盒模式下使用 google html 模板代替对话框,但这不起作用。

当我同时使用 google.script.host.editor.focus()google.script.host.close() 时,它没有将焦点发送回工作表。

【问题讨论】:

  • When I use google.script.host.editor.focus() and google.script.host.close() together。展示你是如何一起使用它们的,以及控制台上是否有任何错误。
  • 控制台上没有错误。对话框关闭。电子表格中未加载任何数据
  • focus(),然后再close()怎么样?
  • 试过了。没用
  • Dialog get closed. No data loaded on spreadsheet 但是焦点在电子表格上对吗?

标签: google-apps-script web-applications


【解决方案1】:

我只是在调用函数后使用成功处理程序关闭我的对话框,并且有效。

<input type="button" value="OK" onclick="google.script.run.withSuccessHandler(google.script.host.close).callNumbers(this.parentNode);google.script.host.editor.focus();" />

这将关闭对话窗口并将焦点返回到电子表格。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多