Skip to main content
Known Participant
January 4, 2022
Answered

Need help with script for required form fields

  • January 4, 2022
  • 1 reply
  • 1446 views

Greetings!

 

I am currently working on a form that asks a "Yes/No" question. If the preparer responds "Yes" to the question, I would like to require information be entered into the explanation field. If they respond "No" then no information is required in the explanation field. 

 

Any help would be appreciated!

This topic has been closed for replies.
Correct answer Nesa Nurani

I would like the "Explanation" field to be required, but only if they checked yes.


As 'custom calculation script' of "Explanation" field use this:

event.target.required = this.getField("4YN").valueAsString == "Y" ? true : false;

1 reply

Nesa Nurani
Community Expert
Community Expert
January 4, 2022

So you want to make "explanation" field required if answer is 'yes' and not required if answer is 'no' or no selections are made?

Can you share some more details, like: what type of fields are yes/no, field names...etc.

Known Participant
January 5, 2022

Hello Nesa!

 

I currently have two check boxes that are named “4YN.”  The check boxes are named the same, but with separate export values (either Y or N).

 

I have the fields set as required so there shouldn’t be a scenario where no selections are made. The only desired outcome is that if the form user checks the “Yes” box, they must insert something into the form field named “Explanation.”

 

Thank you in advance for your willingness to help me out. It is very much appreciated.

Nesa Nurani
Community Expert
Community Expert
January 5, 2022

When you say they must insert something into the form field named “Explanation.” what did you have in mind?

You want to make "Explanation" field required, or just want alert to pop to notify user to fill that field or you want to force them to fill it by setting focus on field(not recommended)?