Livevalidation And Group Of Checkbox, Radio, Select
Solution 1:
It can be done, though LiveValidation will fight you. You can't attach a validator to an input type="radio".
So what I have done is add a dummy input element something like:
<input id="foo" type="text" style="display: none;" value="1" />
to my form, then add a Validate.Custom to that. The custom validation function would be something like
function () {
return $('input[name=myRadioName]:checked').length;
}
This is what I did using the standalone LiveValidation and jQuery; probably can do something similar with prototype.js if you're using that version. One gotcha is that you must assign a value attribute to your dummy input element, because LiveValidation seems to skip inputs that have no value (excepting of course Validate.Presence).
Solution 2:
For a select, you can use it just fine.
<select name="foo" id="foo">
<option value="" selected="selected"></option>
<option value="value1">value1</option>
<option value="value2">value2</option>
</select>
But for radio buttons, it doesn't seem to work.
<input type="radio" name="bar" value="1" />
<input type="radio" name="bar" value="2" />
LiveValidation only works for elements that have an "id", which is not possible with radio buttons. Seems like a limitation of LiveValidation. Anyone has a workaround ?
Solution 3:
I was having this same issue and came up with another way to look at it. I was using my radio group for acesses level -
- Level one
- Level two
So I just added a third level and set it to selected so that field is in essence required with a dummy value if you don't address the field.
- Level one
- Level two
- no access
Post a Comment for "Livevalidation And Group Of Checkbox, Radio, Select"