【问题标题】:HtmlService Spreadsheet form refreshHtmlService 电子表格表单刷新
【发布时间】:2015-12-02 22:42:35
【问题描述】:

我在 Google 工作表上有一个表单 ModalForm,它可以将行插入工作表中。几个月来一直运行良好。从上周提交表单后,表单将消失并且不会重新显示。我不确定为什么。它执行插入电子表格的罚款。我只是永远不会让表单回来插入下一条记录。

在我的索引文件中,表单代码:

<form id="myReceiveForm" name="receive" onsubmit="writeLine()">
  Scanner Name : <input id="user" name="user" type="text" required  /> <br> <br>
  Reference Number: <input id="reference" name="reference" type="text" required  /> <br> <br>
  Location:         <input id="location" name="location" type="text" pattern="[A-Z]{1,3}\-[A-Z]{1,2}\-\d{1,3}\-\d{1,2}" title="Location not in correct format." required/> 
  <button type="button" value="change" onclick="changeLocation()" >Change Location</button><br> <br>
  Product SKU:      <input id="sku" name="sku" type="text" value="" autofocus /> <br> <br> 
                    <input type="submit" value="Submit" >
</form>

<script type="text/javascript">


function onSuccess() {

    document.getElementById("sku").value = '';
    document.getElementById("sku").focus();
    return false;

}

function onFailureM(error) {

     alert("Invalid Sku");
    //alert("SKU" + document.getElementById("sku ").value +" doesn't exist.");
     document.getElementById("sku").value = '';
    document.getElementById("sku").focus();

}


window.writeLine = function () {


 google.script.run
   .withSuccessHandler(onSuccess)
   .withFailureHandler(onFailureM)
   .appendRowstoSheet(document.forms[0]);
} 

</script>

在我的 .gs 文件中:

function openReceiving() {
  var html = HtmlService.createHtmlOutputFromFile('index');
           SpreadsheetApp.getUi().showModalDialog(html, '3PL RECEIVING');

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    从上面的表单标签中删除onsubmit="writeLine()"。更改提交按钮:

    <input type="submit" value="Submit" >
    

    到带有事件的常规按钮:

    <input type="button" value="Submit" onmouseup="writeLine()">
    

    这应该可以解决问题。 2015 年 11 月 12 日,Google 迁移到 IFRAME 模式。

    除非明确指定 NATIVE 模式,否则所有新脚本都将默认为 IFRAME 沙盒模式。

    Google Apps Script Sunset Scedule

    这可能是导致您的问题的原因。表单提交导致表单标签消失。这是在常规 HTML 中已经存在很长时间的预期行为。但是很长一段时间以来,HTML 服务都覆盖了这种行为。现在,IFRAME 模式更像是常规的 HTML 行为。

    如果您需要在最后一个字段更新后提交表单,请在 SKU 输入字段中添加onchange 属性:

    <input id="sku" name="sku" type="text" value="" autofocus onchange="writeLine()"/>
    

    onchange Event - Reference information

    List of all the events

    【讨论】:

    • 我现在遇到的一个问题是我表单中的最后一个字段是使用扫描仪输入数据的。扫描仪扫描后发送回车。我需要这个来提交表格。它在旧版本中做到了。我需要什么活动?因为我没有使用键盘或鼠标来物理按下提交按钮。谢谢。
    • 好问题。尝试使用onchange="" 事件。查看更新的答案。
    猜你喜欢
    • 1970-01-01
    • 2016-02-25
    • 1970-01-01
    • 1970-01-01
    • 2020-10-13
    • 1970-01-01
    • 1970-01-01
    • 2019-01-15
    • 2013-03-19
    相关资源
    最近更新 更多