当我双击提交两次的表单时。它会创建重复的行。如何防止双击?
谢谢!
function doGet(e) {
//Logger.log( Utilities.jsonStringify(e) );
if (!e.parameter.page) {
// When no specific page requested, return "home page"
return HtmlService.createTemplateFromFile('employee').evaluate()
.setTitle('care backup').setSandboxMode(HtmlService.SandboxMode.NATIVE);
}
// else, use page parameter to pick an html file from the script
return HtmlService.createTemplateFromFile(e.parameter['page']).evaluate()
.setTitle('care').setSandboxMode(HtmlService.SandboxMode.NATIVE);
}
答案 0 :(得分:0)
我没有测试过这个,但只是一个选项 - 还设置一个基于时间的触发器来经常运行功能重置?
var recentSubmit = 0;
function doGet(e) {
//Logger.log( Utilities.jsonStringify(e) );
if (recentSubmit = 0){
if (!e.parameter.page) {
var recentSubmit = 1;
// When no specific page requested, return "home page"
return HtmlService.createTemplateFromFile('employee').evaluate()
.setTitle('care backup').setSandboxMode(HtmlService.SandboxMode.NATIVE);
}
// else, use page parameter to pick an html file from the script
return HtmlService.createTemplateFromFile(e.parameter['page']).evaluate()
.setTitle('care').setSandboxMode(HtmlService.SandboxMode.NATIVE);
}
Logger.log("Submitted a form to recently, try again later...");
}
function reset() {
var recentSubmit = 0;
}
答案 1 :(得分:0)
您可以尝试使用createClientHandler.forEventSource().setEnabled(false)。它可以禁用提交按钮。它已被弃用,但现在仍然可以使用。
完整的代码实现示例可在此SO post中找到:
function onOpen() {
var app = UiApp.createApplication();
app.setTitle('My Title');
app.setHeight(150);
app.setWidth(300);
var form = app.createFormPanel();
var flow = app.createFlowPanel();
flow.add(app.createHidden("action", 'action'));
flow.add(app.createLabel('My Label'));
//Submit
var submit = app.createButton('Run', app.createServerHandler('notif').addCallbackElement(form)).setId('run');
var cliHandler = app.createClientHandler().setEnabled().setEnabled(false);
submit.addClickHandler(cliHandler);
flow.add(submit);
form.add(flow);
app.add(form);
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
spreadsheet.show(app);
};
function notif(){
//DO NOTHING. JUST SHOW THE button is DISABLED.
}
点击后,按钮显示为灰色