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

Check combo for "empty" fields

Community Beginner ,
Jan 02, 2018 Jan 02, 2018

Currently working on a script for the verify empty fields before printing to give a warning.

what i purloined and modified from the forum was

// check for empty fields

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.value==" ")) || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);

}

}

if (emptyFields.length>0) {

     app.alert("Important - You must fill in the following fields or your reimburstment will be delayed:\n" + emptyFields.join("\n"));

} else this.print();

I need to add for it to check combo boxes for the answer "-" as that the default setting or empty setting.  Is that possible?

TOPICS
Acrobat SDK and JavaScript , Windows
436
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

correct answers 1 Correct answer

LEGEND , Jan 03, 2018 Jan 03, 2018

One can also use the "defautlValue" property of a field to check for an uncompleted field.

// check for empty fields

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.defaultValue) emptyFields.push(f.name);

}

}

if (emptyFields.length>0) {

     app.alert("Important - You must fill in the following fields or your reimburstment will be delayed:\n" + emptyFields.join("\n"));

} else this.p

...
Translate
Community Expert ,
Jan 02, 2018 Jan 02, 2018

Change this part:

if ((f.type=="text" && (f.value=="" || f.value==" ")) || (f.type=="checkbox" && f.value=="Off"))

To:

if (f.valueAsString==f.defaultValue)

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
LEGEND ,
Jan 03, 2018 Jan 03, 2018
LATEST

One can also use the "defautlValue" property of a field to check for an uncompleted field.

// check for empty fields

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.defaultValue) emptyFields.push(f.name);

}

}

if (emptyFields.length>0) {

     app.alert("Important - You must fill in the following fields or your reimburstment will be delayed:\n" + emptyFields.join("\n"));

} else this.print();

You may have to adjust your code if there is a signature field.

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