dstreet / dependsOn

a jQuery plugin for handling form field dependencies
http://dstreet.github.com/dependsOn
MIT License
106 stars 32 forks source link

"checked" qualifier doesn't work on radio buttons #13

Open srsanborn opened 9 years ago

srsanborn commented 9 years ago

The "checked" qualifier doesn't work on radio buttons as documented.

srsanborn commented 9 years ago

For what it's worth, my current workaround has been to use the values qualifier on a set of radio buttons, like so:

$('#text_field').dependsOn( {'input[name="radio_button_set"]': {values: ['one']}}, {hide: false} );

...but it would be nice to simplify this to depend on the checked state of a specified element vs value-based dependency.

dstreet commented 9 years ago

Thanks for pointing that out. The documentation is incorrect. The checked qualifier is meant to only work on checkboxes. I will consider allowing this qualifier to be used for radio buttons, but since a radio group is meant to represent multiple states of a single property, the values qualifier best fits this need.

dennisdupont commented 9 years ago

This works if you want a specific value, but not if you want to check against unchecked. Rather than have to repeat all possible values (a maintenance headache and not very DRY), I should be able to use {not: [undefined]} (although I'm not sure jquery will normalize all browsers to undefined - better to check for null or empty string also).

lajlev commented 8 years ago

Please update documentation with this for radio buttons. Thanks to @srsanborn

$('#some-element').dependsOn({
  'input[name="radiogroup"]': { values: ['other'] }
});