Copy link to clipboard
Copied
I have a form with a check box that validates that all of the text fields have values. If there is no value, then it displays a JavaScript warning window that says: Error! You must fill in the following fields. The required fields with no data are then listed.
Problem is that if the value is zero it gives the warning. Zero is an acceptable value and I don’t want it to give the warning in this case.
var emptyFields = [];
for (var i=0; i<this.numFields; i++) {
var f= this.getField(this.getNthFieldName(i));
if (f.type!="button" && f.required ) {
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);
}
}
if (emptyFields.length>0) {
app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));
}
Copy link to clipboard
Copied
Replace
f.value == ""
with
f.valueAsString == ""
Copy link to clipboard
Copied
Such an easy solution. Thanks for your help. Works perfectly now.