javascript - jQuery validation plugin - issue with radio buttons -
i using jquery validation plugin validate forms in pages. works smoothly except radio buttons.
i have following code:
$("#theform").validate({ "rules": { "r1" : "required" }, "messages" : { "r1" : { "required" : "foo" } } }); ............ ............ <input type="radio" name="r1" value="1" /> <input type="radio" name="r1" value="2" /> <input type="radio" name="r1" value="3" />
validation works "foo" message shown between first , second radio button. won't do. want after last radio button.
no problem thought, add own label after last radio button:
<input type="radio" name="r1" value="1" /> <input type="radio" name="r1" value="2" /> <input type="radio" name="r1" value="3" /> <label for="r1" class="error" style="display:none">bar</label>
it works "bar" message shown instead. don't want that, want messages inside rules of validation how do that?
how can place error message after last radio button , make use message rules (i.e. "foo")?
you can use errorplacement call when setting options. http://docs.jquery.com/plugins/validation/validate#toptions
errorplacement: function(error, element) { if (element.attr('type') === 'radio') { error.insertafter( element.siblings('input[type="radio"][name="' + element.attr('name') + '"]:last')); } else { error.insertafter(element); } }
Comments
Post a Comment