Skip to main content
Participant
June 28, 2023
Question

PDF not validating value of zero

  • June 28, 2023
  • 1 reply
  • 369 views

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"));

}

This topic has been closed for replies.

1 reply

Bernd Alheit
Community Expert
Community Expert
June 29, 2023

Replace

f.value == ""

with

f.valueAsString == ""

 

Participant
June 30, 2023

Such an easy solution. Thanks for your help. Works perfectly now.