Skip to main content
Participant
June 27, 2024
Answered

Creating a form with multiple checkboxes where at least one, but not all, is required to be checked?

  • June 27, 2024
  • 1 reply
  • 1890 views

I've been googling around trying to figure this out on my own, but everything I find is triggered by a submit or email button.  This form is to be filled out by the applicant and then emailed into their local office so neither of those buttons will do it.

 

For the most part I've set all fields and radio buttons to required and then set up a warning popup when they try and save or print.  But one section of my form asks what the months of use will be, and they can choose "year round", or any number of specific months.  Setting them to "required" will of course trigger the script for each box that isn't filled out, but setting them as not required would risk them missing that section, which would delay the process.  As far as I can tell from looking it up, there is no option to allow selection of multiple radio buttons.  Is there anything I can do to make this work?

This topic has been closed for replies.
Correct answer Thom Parker

Since the form is emailed by the user, there is no simple way to do a whole form validation. But there are two simple solutions.  

1) Provide a form validation button that the user can press voluntarily to verify that all required elements are entered. 

2) Show the validation status somewhere on the form in such a way that it can't be ignored. For example, in the header and footer.  Then you'd also need to highlight the problem fields somehow. And easy solution for this is to change the border or backgroud of fields to red. 

 

These technique require a script, and so will only work with the desktop Acrobat Pro or Reader. 

There is no solution for forms that are filled out on a mobile device. 

 

Now, here is a method to verify that one or more checkboxes is filled in. 

1) Give all the checkboxes that need to be checked together a group name, such as "Section1.Check1", "Section1.Check2",  etc. 

2) the group naming allows all of the check boxes to be accessed at once. Here is a function that returns true if at least one checkbox in the group is checked. It should be placed in a document script. 

 

function ValidateCheckBoxGroup()

{

      return this.getField("Section1").getArray().some(a=>a.value != "Off");

}

This function should be called each time you want to validate the checkbox selection. It could be done in the mouse up/down event for each checkbox, or in a calculation script. 

 

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
June 27, 2024

Since the form is emailed by the user, there is no simple way to do a whole form validation. But there are two simple solutions.  

1) Provide a form validation button that the user can press voluntarily to verify that all required elements are entered. 

2) Show the validation status somewhere on the form in such a way that it can't be ignored. For example, in the header and footer.  Then you'd also need to highlight the problem fields somehow. And easy solution for this is to change the border or backgroud of fields to red. 

 

These technique require a script, and so will only work with the desktop Acrobat Pro or Reader. 

There is no solution for forms that are filled out on a mobile device. 

 

Now, here is a method to verify that one or more checkboxes is filled in. 

1) Give all the checkboxes that need to be checked together a group name, such as "Section1.Check1", "Section1.Check2",  etc. 

2) the group naming allows all of the check boxes to be accessed at once. Here is a function that returns true if at least one checkbox in the group is checked. It should be placed in a document script. 

 

function ValidateCheckBoxGroup()

{

      return this.getField("Section1").getArray().some(a=>a.value != "Off");

}

This function should be called each time you want to validate the checkbox selection. It could be done in the mouse up/down event for each checkbox, or in a calculation script. 

 

 

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