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

Validate all Missing Fields (Not Required Fields)

New Here ,
Aug 07, 2018 Aug 07, 2018

I've found the correct JavaScript for validating required fields upon a document action (Print/Save/Close) with a popup prompt; but I am looking to get rid of the Red Boxes (as they are ugly) by either searching for all blank fields or changing the color of the red box. All fields within the form are required, and as a result the form becomes very clunky. Any suggestions?

TOPICS
Acrobat SDK and JavaScript , Windows
757
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 ,
Aug 07, 2018 Aug 07, 2018

The same script should work, with a simple modification. Can you post what you've tried?

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 ,
Aug 07, 2018 Aug 07, 2018

Hi George,

I'm using the following script below that I found from a different thread- I did not want it to list every field that is missing so I changed it to read "Notice: there are required fields that are missing." That being said, every field on the form is required (with the exception of check boxes/radio boxes).

Please see the script here:

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

    app.alert("Notice: there are required fields that are missing.\n");

}

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 ,
Aug 07, 2018 Aug 07, 2018

Try changing this line:

if (f.type != "button" && f.required ) {

To this:

if (f.type != "button" && f.type != "checkbox" && f.type !== "radiobutton") {

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 ,
Aug 08, 2018 Aug 08, 2018
LATEST

In addition, you should also change this line:

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

To:

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

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