UI转换为HTML,转换不会将日期写入表单 [英] UI to HTML, conversion will not write a date to the sheet

查看:118
本文介绍了UI转换为HTML,转换不会将日期写入表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图复制Pieter Jaspers提出的关于将表单从UIApp转换为HTML的问题。原始问题是:



Mogsdad回答的HTML内联表单格式问题



到目前为止,我所使用的代码都是必需的部件数量,一张表格和两张.gs表格。我检查了拼写错误,并且我试着编辑每一行以查看我得到的内容和位置,但是以我有限的经验,我正在画空白。唯一的小成功是,如果我在代码编辑器中运行函数InsertInSS()。这会在正确的电子表格正确的单元格中张贴未定义一词,但不是我正在尝试做的日期!



 <! - 使用模板化HTML打印scriptlet导入常用样式表。 - > 
<?!= HtmlService.createHtmlOutputFromFile('Stylesheet')。getContent(); ?>
< html>
< body>
< div>
<! - 页眉标题& '完成警告 - >
< span class =grey>< b> ProReactive Log Form v3.0.74< / b>< / span>
< h4>完成所有栏位以确保表格已成功处理< / h4>
< div class =block>
<! - 第一个输入框已创建 - >
< div class =inline form-group>
< label form =date>日期< / label>
< input type =dateid =datestyle =width:125px;>
< / div>
< / div>
< / div>
<! - 完成字段结束,使用提交按钮完成表单 - >
< button class =shareonclick =runGoogleScript()>提交< / button>
< / body>
< / html>

< script>
函数onSuccess(argReturnValue){
alert('was successful'+ argReturnValue);
//屏幕上的ResetFields
Document.getElementById(date)。value =;
}

函数runGoogleScript(){
logger.log('v3.0.74 ran!');
var inputValue = document.getElementById(date)。value;
google.script.run.withSuccessHandler(onSuccess)
.InsertInSS(inputValue);
};

< / script>

Code.gs:

 函数doGet(e){

return HtmlService.createTemplateFromFile('myForm')
.evaluate()
.setTitle('ProReactiveLog')
.setSandboxMode(HtmlService.SandboxMode.NATIVE);
};

和seperate.gs:

 函数InsertInSS(argPassedInName){
var ssKey ='1cZuEMDrIyzIFm4lGCT20s-Wpv27o0hbbZAsxD1WJFL8';

var SS = SpreadsheetApp.openById(ssKey);
var Sheet = SS.getSheetByName('LOG');
Sheet.getRange(Sheet.getLastRow()+ 1,1,1).setValue(argPassedInName);

}

任何想法我错了?所有帮助一如既往,非常感谢。

解决方案

Apps脚本HTML应用程序不允许允许date对象传递给服务器。



google.script.run参数文档



文档说明:


如果您尝试传递除表单或其他禁止类型(包括对象或数组内的禁用类型)的Date,Function,DOM元素,请求失败。 $ b

您需要将日期作为字符串传递。将日期转换为客户端代码中的字符串,并在服务器代码中将其转换回日期(如果需要)。但是,即使您将电子表格中的值设置为字符串,也可能会被强制转换回日期,而无需执行任何操作。特别是如果您将该列定义为电子表格中的日期。


I am trying to replicate a question posed by Pieter Jaspers regarding a conversion of a form from UIApp to HTML. The original question is:

Original question by Pieter Jaspars answered by Sandy Good

If I replicate the code exactly I get the correct result, but when I try to recreate my inline form and amalgamate the two I am not getting a result. The inline form question is here:

HTML inline form formatting question answered by Mogsdad

The code I have so far is in the requisite number of parts, a form and two .gs sheets. I have checked for spelling mistakes and I have tried editing out each line to see what and where I get, but with my limited experience I am drawing a blank. The only minor success is if I run the function InsertInSS() from within the code editor. This posts the word "undefined" in the correct cell in the correct spreadsheet, but not the date as I am trying to do!

Form:

<!-- Use a templated HTML printing scriptlet to import common stylesheet. -->
<?!= HtmlService.createHtmlOutputFromFile('Stylesheet').getContent(); ?>
<html>
  <body>
  <div>
  <!-- Page header title & 'completion warning -->
  <span class="grey"><b>ProReactive Log Form v3.0.74</b></span>
  <h4>Complete ALL fields to ensure the form is processed successfully</h4>
  <div class="block">
  <!-- First input box created -->
  <div class="inline form-group">
  <label form="date">Date</label>
  <input type="date" id="date" style="width: 125px;">
  </div>
  </div>
  </div>
  <!-- End of fields for completion, finish form with submission button -->
  <button class="share" onclick="runGoogleScript()">submit</button>
  </body>
  </html>

  <script>
  function onSuccess(argReturnValue){
      alert('was successful ' +argReturnValue);
      //ResetFields on Screen
      Document.getElementById("date").value = "";
      }

  function runGoogleScript() {
      logger.log('v3.0.74 ran!');
      var inputValue = document.getElementById("date").value;
      google.script.run.withSuccessHandler(onSuccess)
      .InsertInSS(inputValue);
      };

  </script>

The Code.gs:

function doGet(e) {

  return HtmlService.createTemplateFromFile('myForm')
  .evaluate()
  .setTitle('ProReactiveLog')
  .setSandboxMode(HtmlService.SandboxMode.NATIVE);
};

and the seperate.gs:

function InsertInSS(argPassedInName) {
  var ssKey = '1cZuEMDrIyzIFm4lGCT20s-Wpv27o0hbbZAsxD1WJFL8';

  var SS = SpreadsheetApp.openById(ssKey);
  var Sheet = SS.getSheetByName('LOG');
  Sheet.getRange(Sheet.getLastRow()+1,1,1).setValue(argPassedInName);

}

Any ideas where I am going wrong? All help as ever, greatly appreciated.

解决方案

An Apps script HTML App, will not allow a date object to be passed to the server.

google.script.run Parameter Documentation

The documentation states:

Requests fail if you attempt to pass a Date, Function, DOM element besides a form, or other prohibited type, including prohibited types inside objects or arrays.

You will need to pass the date as a string. Convert the date to a string in client side code, and convert it back to a date, if need be, in the server code. However, even if you set the value in the spreadsheet as a string, it may get coerced back into a date without you needing to do anything. Especially if you have that column defined as a date in the spreadsheet.

这篇关于UI转换为HTML,转换不会将日期写入表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆