【问题标题】:Form validation and input field of type file in Html ServiceHtml Service中文件类型的表单验证和输入字段
【发布时间】:2013-12-20 10:26:10
【问题描述】:

我正在尝试使用 HTML 服务应用程序脚本将标准 html5 表单验证(使用必需属性和提交按钮)放在带有“文件”输入字段的表单中。

我的问题是使用提交按钮将 blob 文件传递​​给应用程序脚本函数。如果我放置一个普通按钮,我将失去 html5 的标准验证。如果我使用提交按钮,则不会通过“google.script.run”语句将任何内容传递给应用程序脚本函数。

本教程的example 使用普通按钮,但这样我无法对必填字段使用表单验证。

我该如何处理?从现在开始,我必须使用提交按钮和 onclick 事件,并手动检查是否插入了必填字段(在按钮调用的应用程序脚本函数中)。

【问题讨论】:

    标签: google-apps-script


    【解决方案1】:

    将您的代码放在 onSubmit 表单事件上,并确保以 return false 结束 onSuccessHandler 函数。

    <script>
        function updateUrl(url) {
             var div = document.getElementById('output');
             div.innerHTML = '<a href="' + url + '">Got it!</a>';
             return false;
        }
    </script>
    <form id="myForm"
      onSubmit="return google.script.run
        .withSuccessHandler(updateUrl)
        .processForm(this.parentNode);">
     <input required name="myFile" type="file" />
     <input type="button" value="Submit" />
    </form>
    <div id="output"></div>
    

    【讨论】:

      猜你喜欢
      • 2014-02-12
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 2011-03-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多