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

Script to detect unfilled fields wont detect unfilled drop downs, please help!

New Here ,
Jan 17, 2018 Jan 17, 2018

Copy link to clipboard

Copied

I'm used the script below to detect unfilled fields on my forms. It works great however it can't detect unfilled drop downs they are set to be required. Any help would be greatly appreciated!

var emptyFields = [];

for (var i=0; i<this.numFields; i++) {

     var f= this.getField(this.getNthFieldName(i));

     if (f!=null && 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 complete the following fields:\n" + emptyFields.join("\n"));

}

TOPICS
Acrobat SDK and JavaScript , Windows

Views

325

Translate

Translate

Report

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

Community Expert , Jan 17, 2018 Jan 17, 2018

I wrote this code, but that's an old version of it. Replace this line:

if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);

With:

if (f.valueAsString==f.defaultValue) emptyFields.push(f.name);

Votes

Translate

Translate
Community Expert ,
Jan 17, 2018 Jan 17, 2018

Copy link to clipboard

Copied

The code checks only text fields and check boxes.

Votes

Translate

Translate

Report

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 ,
Jan 17, 2018 Jan 17, 2018

Copy link to clipboard

Copied

I wrote this code, but that's an old version of it. Replace this line:

if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);

With:

if (f.valueAsString==f.defaultValue) emptyFields.push(f.name);

Votes

Translate

Translate

Report

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 ,
Jan 17, 2018 Jan 17, 2018

Copy link to clipboard

Copied

LATEST

Thank you! I've been using the original code for a while now, thanks for writing it. 

Votes

Translate

Translate

Report

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