We have a registration form that asks for demographic information with the additional option to not provide any information. However, to keep our numbers adding up properly, we want to require you to enter all information if you select any demographics. A rendering of the form:
- Gender
- ( ) Male
- ( ) Female
- Disabilities?
- ( ) Yes
- ( ) No
- Race
- ( ) A
- ( ) B
- ( ) C
- ( ) I do not wish to provide demographic information
We want to allow selection of ‘I do not wish…’ and all options, e.g. ‘Male/Yes/A’, but not partial answers, e.g. ‘Female/C’.
How can we structure the .validate() rules and options to achieve this goal? Ideally, we would have a single label show/hide if your response is not sufficient.
Additional information:
- Using the jQuery Validation Plugin
- Demographics types are dynamically created from a database list
I’m assuming that you are using the jQuery validation plugin. If so, what you want is a custom require rule with a dependency check that allows you to make the inputs required iff the user does not choose to opt out. You might want to have a click handler on the opt-out that clears the other fields so that you don’t have to check for partial entries when the user does choose to opt out.