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

Conditional Required Fields

Community Beginner ,
Feb 26, 2017 Feb 26, 2017

I have a form that will be submitted via email.

I have a number of Required Fields on the form that are validated automatically prior to submission, but there is one section that's a bit tricky and may require some JavaScript that I haven't been able to work out despite searching these forums.

There are 3 checkboxes on my form that work a bit like radio buttons, but not.

Checkboxes "A" and "B" can be selected independently or together, but checkbox "C" can only be selected on it's own.

I have a JavaScript to automatically de-select both "A" and "B" if checkbox "C" is selected.

I have another JavaScript that automatically de-selects "C" if either "A" or "B" (or both) are selected.

This requirement prevents me from making any of these checkboxes "Required Fields"

But I need to verify that at least one of the three boxes is selected before the form can be submitted.

Any help would be greatly appreciated.

Thanks, Steve

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

Community Expert , Feb 27, 2017 Feb 27, 2017

The most basic code would be something like this:

if (this.getField("A").value=="Off" && this.getField("B").value=="Off" && this.getField("C").value=="Off") {

    app.alert("You must tick either \"A\", \"B\" or \"C\".",1);

} else this.submitForm({cURL: "mailto:me@email.com"});

Translate
Community Expert ,
Feb 27, 2017 Feb 27, 2017

You'll need to perform this validation yourself, using a script. Basically it will just need to look into the values of all three fields and make sure that at least one of them is ticked.

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 Beginner ,
Feb 27, 2017 Feb 27, 2017

I'm still a bit of a novice with JavaScript. Learning as I go. Would you mind giving a bit more info on how to do that?

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 ,
Feb 27, 2017 Feb 27, 2017

The most basic code would be something like this:

if (this.getField("A").value=="Off" && this.getField("B").value=="Off" && this.getField("C").value=="Off") {

    app.alert("You must tick either \"A\", \"B\" or \"C\".",1);

} else this.submitForm({cURL: "mailto:me@email.com"});

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 Beginner ,
Feb 27, 2017 Feb 27, 2017

Thanks. Will give it a go.

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 Beginner ,
Mar 16, 2017 Mar 16, 2017

Works perfect. Thanks.

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 ,
Sep 26, 2017 Sep 26, 2017

I've tried this code and it works great. I get a popup box if one of my check boxes is not selected, but is there a way to make it "required" to check one of the check boxes so that the PDF can't be saved unless one of the check boxes is selected?

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 ,
Sep 26, 2017 Sep 26, 2017

You can't prevent the file from being saved. You can display an error message or even force the saved file to be blank, though.

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 ,
Sep 26, 2017 Sep 26, 2017

Thanks for the info and for replying so quickly.

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 ,
Sep 26, 2017 Sep 26, 2017

No, saving is nothing to do with submitting, and a script can't stop saving. Thank goodness.

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 ,
Oct 06, 2017 Oct 06, 2017
LATEST

I have check boxes for "Business" or "Residential". I want checking business box to then require the EIN (employer identification number) field to be populated, but not required if residential box is checked.  If residential box is checked, I want the fields "D.O.B" and Driver License #" to be required;  but not enforced if business is checked.

Advice?

Thank you.

P.S. Im using acrobat pro DC - where can script be added? couldn't find action area under field properties.

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