【发布时间】:2020-09-09 15:13:56
【问题描述】:
我目前正在将用户通过 google 表单输入的日期与今天的日期进行比较,如果日期尚未出现,我想停止将表单数据插入到 google 响应电子表格中。我已经用谷歌搜索了这个,但找不到类似于具有 e.preventDefault() 的 DOM 的东西。这是我的代码在谷歌脚本编辑器中的样子:
//first, verify the date of the submission is not before the date of the game (has not happened yet)
var todayDate = new Date();
var gameDate = new Date(ogkGameDate);
if (gameDate < todayDate)
{
//send an email to admin and user that submission was rejected because the game date is in the future.
var subject = "WFRA Online Game Keeping Submission";
var message = "Hello! Thank you for submitting to the online game keeping system. \n";
message += "\n Unfortunately, the submission was rejected because this game has not yet occurred:";
message +="\n Game Keeper: " + ogkGameKeeper;
message +="\n Game Date: " + gameDate;
message +="\n Submission Date: " + todayDate;
//message += "\n Administrators can view the submission sheet at " + ogkURL + " \n";
message += "\n Please reply to this email if you experience technical issues. \n";
// Send yourself an email with a link to the document.
GmailApp.sendEmail("wfringette@gmail.com", subject, message,{bcc: "thetroutlakemonster@gmail.com", replyTo: "webmaster@westferrisringette.ca"});
//reject the submission to the sheet
//HERE IS WHERE I WOULD LIKE TO CANCEL THE EVENT TO AVOID DATA INPUT TO THE SPREADSHEET
//exit the code
return; }
提前感谢您的任何建议!
【问题讨论】:
-
这段代码是如何触发的?
-
您想阻止用户提交表单,还是阻止目标电子表格的填充/表单提交时触发脚本?
-
我的代码是在我的谷歌表单的 onFormSubmit 中触发的,我的目标是防止电子表格的填充。非常感谢
-
我刚刚发现我可以清除活动范围,然后什么都没有通过。这只是糟糕的编程吗?
-
您的编码是绑定到表单还是电子表格?我建议您创建一个minimal reproducible example 这将有助于使答案更具体。
标签: google-apps-script google-sheets triggers google-forms preventdefault