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

Acrobat forms | JS to trigger a list of AND/OR fields to be completed after a check box?

New Here ,
Nov 10, 2019 Nov 10, 2019

Hi, I have the JS on a mouse up:

this.getField("Text Box 1").required = event.target.value!="Off";

to get a field (Text Box 1) to be required to be filled in if the check box is ticked, when preparing forms in Acrobat.

But I'm trying to find a way that it's one of (or up to) four boxes that needs to be filled in if the check box is ticked, not just one.

Can anyone help me with what  the script would be to have a list of "text Box 1" AND/OR "text box 2" AND/OR "Text Box 3" please?

Having a "," between the values doesn't seem to work and I'm still learning JS - so help is much apprecaited, thank you 🙂

TOPICS
Create PDFs , PDF forms
656
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 ,
Nov 10, 2019 Nov 10, 2019

First, you need to clearly state the desired behavior.  "And/Or" is ambiguous because "AND" and "OR" are different things. So your description needs to cover all cases, for example: when the checkbox A is checked fields x,y and z become required, when the checkbox A is unchecked fields x,y and z become not-required. You say "up to". What does this mean? are there 4 text boxes and in different situations different ones need to be required?  Be exact.

 

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Nov 11, 2019 Nov 11, 2019

Thanks Thom.

Yes sure. To clarify. I have a 'Yes' and 'No' check box. If they check 'Yes', then it needs them to fill in at least one of the 6 text boxes below, hence the and/or (but understand that that could be ambiguous). They can fill in 1, 2, 3, 4, 5 or 6 or more than one in any combination, but at least one. If "no' then, ideally, they should not be able to fill in any of the 6 boxes.

So I was thinking it was a case of adding in the other values 'Text box 1", "text box 2" etc but this didn't work as I don't yet know enough about JS.

Hopefully that helps explain it. Thanks for your help.

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 ,
Nov 11, 2019 Nov 11, 2019
LATEST

You have a complex/dynamic requirement that goes beyond the standard "required" behavior, so as Try says, a custom validation script is the way to go. How is this form being submitted? For the regular "required" property, the submit triggers the validation. If the validation fails, then the form doesn't submit and the user gets a message to fill all required fields. But there are other ways to do this. For example, the validation script could be used to change the backgroud of the 6 fields to red until at least one is filled out. Or something along these lines. The methodology depends on how the form is expected to be used.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 ,
Nov 11, 2019 Nov 11, 2019

The required property doesn't work that way. If you define multiple fields to be required (that's not part of a group) then they all need to be selected. For what you're describing you would need to use a custom validation script to check that at least one of the fields is filled in before submitting the form.

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