Baumann Baumann - 1 year ago 96
jQuery Question

validate form required only if option radio is selected with parsleyjs

I want to validate a form with parsleyjs.

My problem is I want to validate a block of (3 inputs) only if a input radio is selected.

Here is a image:

enter image description here

By default, no option is selected.

If I choose option 1, nothing need . Validation is ok.

If I choose option 2, I need to validate 3 fields more (I have the validations working: required) only when the option 2 is selected.

I have been reading the docs but could not find the solution.

Solved by myself adding and removing


Answer Source

I finally solved it, by adding required prop to each input when option 2 is selected, and removing required prop if option 1 is selected.

// Option 2
$( '#inputId' ).prop( 'required', true );

// Option 1
$( '#inputId' ).prop( 'required', false );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download