[英]How do I create a pop up box in Google App script?
基本上这是我的问题:
如何使用带有HTML服务的Google App脚本创建弹出窗口或对话框。
我正在Google脚本文件(适用于HTML文件)中进行很多验证,我只需要快速告诉用户错误,然后他们就可以调整其形式并继续进行...这是我到目前为止的验证尝试。 我试图只使用javascript alert()函数,但是它什么也没做。
if(date == ""){
alert("please select a date");
}else if(teacher == ""){
alert("please put your name");
}else if(group == ""){
alert("Please enter a group");
}else if(notes == ""){
alert("Please write where the tech is being used in the notes");
}else if(events.length != 0){
window.alert("It appears that the slot your trying to book is taken");
}else{
我希望我可以通过这种方式进行验证,而不必执行全新的验证方法(很可能来自HTML文件)
如果您的验证脚本(如果elseif语句)在Code.gs文件中,则警报功能将不起作用。
您要做的是使用.withSuccessHandler将错误消息抛出到html脚本中的google.script.run函数中,然后从那里进行警报。
由于警报是从html(而不是.gs文件)中调用的,因此它将起作用。
假设上面的脚本在一个名为validateForm()的函数中,并且您正在表单提交按钮上调用它,则代码将类似于以下内容:
HTML文件
// some codes and scripts here
Google.script.run.withSuccessHandler(showAlert).validateForm(this.form);
function showAlert(stringFromCodeGs) {
if (stringFromCodeGs != false) {
alert(stringFromCodeGs);
}
GS文件
function validateForm(formObject) {
if(formObject.date == ""){
return "please select a date";
}else if(formObject.teacher == ""){
return "please put your name";
}
// your other else if here
}else{
//your code to process form here
return false;
}
它的作用是将错误消息返回(返回)到您的google.script.run,然后将其用作成功处理程序的参数-在此示例中,是showAlert()函数,由自动调用。 withSuccessHandler()。
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.