Skip to main content
Participating Frequently
January 2, 2018
Answered

Check combo for "empty" fields

  • January 2, 2018
  • 2 replies
  • 475 views

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?

This topic has been closed for replies.
Correct answer gkaiseril

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.

2 replies

gkaiserilCorrect answer
Inspiring
January 3, 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.print();

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

try67
Community Expert
Community Expert
January 2, 2018

Change this part:

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

To:

if (f.valueAsString==f.defaultValue)