我发现了一个代码,如果必填字段为空,则会在pdf中推送消息。
但是,当涉及到条件其他必填字段时;当某个字段不为空时,弹出消息将需要一些子字段。
我似乎正在遇到一些无法使用的阻止程序。不确定该怎么做,因为我对JavaScript不太熟悉。希望有人可以帮助我。预先感谢
//code for pushing message when a required field is empty (Code that works)
var fld1 = this.getField('COMPANY NAME');
var fld2 = this.getField('ACCOUNT NUMBER');
var fld3 = this.getField('EMAIL ADDRESS');
var errMsgs = [];
var firstBadField = null;
if (fld1.valueAsString == fld1.defaultValue) {
errMsgs.push("Please key in your company name.");
firstBadField = fld1;
}
if (fld2.valueAsString == fld2.defaultValue) {
errMsgs.push("Please enter your account number.");
firstBadField = fld2;
}
if (fld3.valueAsString == fld3.defaultValue) {
errMsgs.push("Please enter your email address .");
firstBadField = fld3;
}
if (errMsgs.length>0) {
app.alert(errMsgs.join("\n\n"));
firstBadField.setFocus();
//Code for when field no_1 is not empty then field Name_1, Name_2, and Name_3 is required (Code which is not working)
var rgEmptyTest = /^\s*$/;
function testSelfRequiredField (no_1, NAME_1) {
if (rgEmptyTest.test(no_1)){
this.getField(NAME_1).required = true;
this.getField(NAME_2).required = true;
this.getField(NAME_3).required = true;
this.getField(NAME_1).value = "";
this.getField(NAME_2).value = "";
this.getField(NAME_3).value = "";
errMsgs.push("Please enter User name.");
} else {
this.getField(NAME_1).required = false;
this.getField(NAME_2).required = false;
this.getField(NAME_3).required = false;
}
}
} else {
var cToAddr = "EMAIL@gmail.com";
var cSubLine = " Update Form - " + this.getField("ACCOUNT NUMBER").value + this.getField("COMPANY NAME").value;
var cBody = " Details for Request, Account - " + this.getField("ACCOUNT NUMBER").value + this.getField("ACCOUNT NUMBER").value +"," + this.getField("COMPANY NAME").value + " , " + this.getField("COMPANY NAME").value +" , "+ this.getField("COMPANY NAME").value;
this.mailDoc({
bUI: true,
cTo: cToAddr,
cSubject: cSubLine,
cMsg: cBody
});
}