Google表单脚本&HTML不能执行被调用的脚本

Google Form script & HTML won't execute the called script

本文关键字:脚本 调用 执行 HTML 表单 Google 不能      更新时间:2023-09-26

我使用一个html页面在Google脚本中创建了一个表单,然后调用javascript函数,如下所示。当我运行应用程序时,表单加载得很好,但它不会执行脚本。我该怎么做呢?

下面是我要做的一个例子:

<html>
  <!--Create Sign Out Form-->
  <form id="signOut">
    <div>
      Destination: 
      <select name="destination">
        <option value="lunch">Lunch</option>
        <option value="meeting">Client Meeting</option>
        <option value="vacation">Vacation</option>
        <option value="sick">Out Sick</option>
        <option value="personal">Personal</option>
        <option value="home">Working from Home</option>
        <option value="scedule">Reduced Schedule</option>
      </select>
    </div>
    <div>
      Supervisor: 
      <select name="supervisor" onselect="google.script.run.withUserObject(this.parentNode).populate(destination)"></select>
    </div>
    <div>
      Start Date: 
      <input type="date" name="startDate" onselect="google.script.run.withUserObject(this.parentNode).SignOutLibrary.dateSelect()"/>
    </div>
    <div>
      End Date: 
      <input type="date" name="endDate" onselect="google.script.run.withUserObject(this.parentNode).SignOutLibrary.dateSelect()"/>
    </div>
    <div>
      Details: 
      <textarea type="text" name="details" style="width: 150px; height: 75px;"></textarea>
    </div>
    <div>
      <input type="button" value="Submit"
        onclick="google.script.run
             .sendRequest(this.parentNode)"/>
    </div>
  </form>
</html>

和它应该调用的脚本:

function doGet() {
  // Uses html form
  return HtmlService.createHtmlOutputFromFile('request_form');
}

SignOutLibrary:

function dateSelect() {
  var app = UiApp.createApplication();
  var handler = app.createServerHandler("change");
  var date = app.createDatePicker().setPixelSize(150, 150).addValueChangeHandler(handler).setId("date");
  app.add(date);
  return app;
}
function change(eventInfo) {
  var app = UiApp.getActiveApplication();
  app.add(eventInfo.parameter.date);
  return app;
}

尝试更改所有这些。在你的代码中使用this.form

我迅速查看了文档,也许它会工作,对不起,但我现在不能测试我的答案

您没有显示populate() -希望您有这样的函数。如果您这样做,那么您的下一个任务将是找到一种方法来获得作为参数传递的destination的值。在现在时,它是没有定义的。参见使用JavaScript获取下拉列表中的选定值?

你不能直接使用脚本运行器调用库函数,参见Private functions部分。您需要在"本地"gs中添加中间函数,以便与库函数(如SignOutLibrary.dateSelect())进行接口。

该库使用UiApp,而其余代码使用Html Service。选择其中一个,因为你不能像这样把它们混合在一起。