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

If box checked, required fields no longer required - how do I do this?

Explorer ,
Mar 26, 2019 Mar 26, 2019

Copy link to clipboard

Copied

I am creating a form with three checkboxes and several form fields. If the first two boxes are checked, the user needs to complete certain sections of the form before they can print. If the third box is checked, they only need to print the form and do not need to continue filling out the form. I added a print button at the bottom to run a script that if the required fields do not have data, the form will not print. But, how do I eliminate this warning if the user checks box #3? I've tried hiding the fields but I still receive the warning that I need to fill out the required fields even if they are hidden. 

This is the script I am using from Try67, which works great for warning the user to fill in the required fields:

var emptyFields = []; 

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

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

    if (f==null || f.type=="button") continue; 

    if (f.required && f.valueAsString==f.defaultValue) { 

        f.strokeColor = color.red;  //Highlights the required fields with red outline 

        emptyFields.push(f.name); 

    } else f.strokeColor = color.gray; //Highlights the filled in fields with gray outline 

 

if (emptyFields.length>0) { 

    app.alert("WAIT! You must fill in all of the required fields before printing this form"); 

} else this.print(); 

Thanks!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

573

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 , Mar 26, 2019 Mar 26, 2019

You can do it either in this code (not recommended) or via the MouseUp event of the check-box, which will change the required property of the fields, based on its new value (a better approach).

The basic code to do that would be this (as the MouseUp event of the check-box field):

this.getField("Name of other field").required = (event.target.value!="3");

Votes

Translate

Translate
Community Expert ,
Mar 26, 2019 Mar 26, 2019

Copy link to clipboard

Copied

You can do it either in this code (not recommended) or via the MouseUp event of the check-box, which will change the required property of the fields, based on its new value (a better approach).

The basic code to do that would be this (as the MouseUp event of the check-box field):

this.getField("Name of other field").required = (event.target.value!="3");

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
Explorer ,
Mar 26, 2019 Mar 26, 2019

Copy link to clipboard

Copied

LATEST

Thank you so much! To simplify things, I changed all of the required fields to "Required.Name" and so on. Then I only had to enter "Required" into the name field in the code. Worked just like I needed it to!

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