Googleフォームでは、フィールドをチェックする検証チェックを作成しました.カウントを超えた場合は、フォームの送信を停止し、エラーについてユーザーに警告する必要があります. div にエラー テキストを追加することはできますが、フォームの送信を停止することはできません。
フォームの送信を停止するにはどうすればよいですか。e.preventDefault() を試しましたが、うまくいきませんでした。誰か助けてください。Googleフォームでフォーム送信のイベントで呼び出されるコードを添付しました。
function onFormSubmit(e) {
Logger.log("test log", "testing");
var timestamp = e.values[0];
var programname = e.values[1];
var center = e.values[2];
var fullname = e.values[3];
var board = e.values[4];
var programtype = e.values[5];
var programobjective = e.values[6];
var calltoaction = e.values[7];
var begindate = e.values[8];
var enddate = e.values[9];
var marketing = e.values[10];
var budget = e.values[11];
var expectedparticipation = e.values[12];
var registrationfee = e.values[13];
var announcement = e.values[14];
var insightannouncement = e.values[15];
var additionallanguage = e.values[16];
var checklist = e.values[17];
var speakerprofile = e.values[18];
var noticeboarditem = e.values[19];
var toAddress = e.values[20];
var programcategory = e.values[21];
var liability = e.values[22];
var datesofannouncement = e.values[23];
var explaination = e.values[24];
var additionalquestion = e.values[25];
var location = e.values[26];
var externalpartners = e.values[27];
var intergenerational = e.values[28];
var announcementlanguage = e.values[29];
// var app = DocumentApp.getUi();
var app = UiApp.getActiveApplication();
Logger.log("test log in checkAnnouncement: " + announcement + " insight " + insightannouncement, "testing");
// var announcement = e.values[14];
//var insightannouncement = e.values[15];
//var toAddress = e.values[20];
//var htmlBody = "Thank you for your <b>Program Package</b> report submitted on <i>";
//var subject = "test subject";
Logger.log(announcement, "testing");
Logger.log(insightannouncement, "testing");
// Logger.log(toAddress, "testing");
announcement = announcement.replace(/(^\s*)|(\s*$)/gi,"");
announcement = announcement.replace(/[ ]{2,}/gi," ");
announcement = announcement.replace(/\n /,"\n");
insightannouncement = insightannouncement.replace(/(^\s*)|(\s*$)/gi,"");
insightannouncement = insightannouncement.replace(/[ ]{2,}/gi," ");
insightannouncement = insightannouncement.replace(/\n /,"\n");
if(announcement.split(' ').length > 3)
{
app.getElementById('entry_15').setText("*Announcement should be less than 30 words").setStyleAttribute("color", "#F00");
e.preventDefault();
}
else if(insightannouncement.split(' ').length > 5)
{
app.getElementById('entry_32').setText("*insightAnnouncement should be less than 50 words").setStyleAttribute("color", "#F00");
e.preventDefault();
}
}