Skip to main content
sw777
Known Participant
February 27, 2017
Answered

Conditional Required Fields

  • February 27, 2017
  • 1 reply
  • 1950 views

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

This topic has been closed for replies.
Correct answer try67

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

1 reply

try67
Community Expert
Community Expert
February 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.

sw777
sw777Author
Known Participant
February 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?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
February 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"});