Livevalidation and a group of radio checkboxes, select

The livevalidation script is great for validating forms, but as you rely on a group of checkboxes, radio and choices. see website: http://www.livevalidation.com/

+4
source share
3 answers

This can be done, although LiveValidation will fight you. You cannot attach a validator to input type = "radio".

So what I did, add a dummy input element something like:

<input id="foo" type="text" style="display: none;" value="1" /> 

into my form, then add Validate.Custom to this. Custom validation function will look like

 function () { return $('input[name=myRadioName]:checked').length; } 

This is what I did with standalone LiveValidation and jQuery; can probably do something similar with prototype.js if you use this version. One of them is that you must assign a value attribute to your dummy input element, because LiveValidation skips inputs that don't matter (except, of course, Validate.Presence).

+2
source

You can use it just fine for a selection.

  <select name="foo" id="foo"> <option value="" selected="selected"></option> <option value="value1">value1</option> <option value="value2">value2</option> </select> 

But for switches this does not work.

 <input type="radio" name="bar" value="1" /> <input type="radio" name="bar" value="2" /> 

LiveValidation only works for items with an "id", which is not possible using radio buttons. Sounds like a limitation of LiveValidation. Does anyone have a workaround?

+1
source

I had the same problem and tried to look at it in a different way. I used my radio band for acesses level -

  • Level 1
  • Level 2

So, I just added a third level and set it to my choice so that the field is mostly required with a dummy value if you are not accessing the field.

  • Level 1
  • Level 2
  • No access
0
source

All Articles