jQuery-Form-Validator icon indicating copy to clipboard operation
jQuery-Form-Validator copied to clipboard

Dependent Validation with RadioButtons

Open JakenHerman opened this issue 8 years ago • 6 comments

I have an input that should depend on a radio button before requiring validation, but the input seems to always be required regardless of the radiobutton. Code below.

<label for="stipend">Stipend Amount</label>
<input id="stipend" type="radio" name="is-paid" value="Stipend No">
<label for="stipend-amount" class="hidden">Stipend Amount</label>
<input placeholder="" id="stipend-amount" name="stipend-amount" type="text" data-validation="required" data-validation-depends-on="is-paid" data-validation-depends-on-value="Stipend Yes" />

Seems that #stipend-amount is always required, and not only required when #stipend value = Stipend Yes.

Syntax error or does dependent validation not work with radio buttons?

JakenHerman avatar Jul 26 '16 22:07 JakenHerman

I can't seem to make this to work, I can't even find a working sample of this from the actual guide http://www.formvalidator.net/#logic_oneof

I already tried to copy the html above but still no luck

jezguitarist30 avatar Dec 13 '16 09:12 jezguitarist30

Sorry my fault, I didn't know I had to download the entire folder which includes logic.js I just grab the cdn version.

jezguitarist30 avatar Dec 13 '16 09:12 jezguitarist30

wondering if this has been fixed yet? I'm having the same issue.

beckysoll avatar Feb 21 '17 20:02 beckysoll

I can't get this working, and I can't find documentation to tell me how to do it. I have a multiple radio with options "delivery" and "collection". If delivery is checked then Address should be required.

<input name="delivery" id="delivery-0" value="Delivery" checked="checked" type="radio"> data-validation="required" data-validation-depends-on="delivery-0" data-validation-depends-on-value="delivery" type="radio"

What am I doing wrong? Thanks

ResetOnset avatar Nov 21 '17 15:11 ResetOnset

@ResetOnset try changing data-validation-depends-on="delivery-0" to data-validation-depends-on="delivery" to reference the name attribute of the input, not the id.

chrisjohnstone avatar Jun 11 '18 09:06 chrisjohnstone

Thanks for your suggestion Chris, but I'm not sure that would work as I have two radios with the name "delivery". Here's my existing code (which I'm guessing is wrong!):

`

`

If people are collecting we don't need their address, but if they need delivery (id delivery-0 above) then the address field in the form should be required. Thanks again.

ResetOnset avatar Jun 14 '18 10:06 ResetOnset