Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

PDF not validating value of zero

New Here ,
Jun 28, 2023 Jun 28, 2023

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

}

TOPICS
JavaScript , PDF forms
327
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 28, 2023 Jun 28, 2023

Replace

f.value == ""

with

f.valueAsString == ""

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 30, 2023 Jun 30, 2023
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines