Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery validation: Custom rule not called

Here is my simple validation code for testing:

    jQuery.validator.addMethod("oneTypeChecked", function (value, element) {
        return false; //$(':checkbox:checked') > 0
    }, "Check one or more type");

    $("#RequestCreateForm").validate({
        rules: {
            ChkBoxType1: { oneTypeChecked: true }
        }
    });

But my method oneTypeChecked is never called when I submit form. Why?

Here is my HTML code:

<div class="editor-field">
    <input type="checkbox" id="ChkBoxType2" name="requestTypeIds2" value="2">Type 2     
    <input type="checkbox" id="ChkBoxType1" name="requestTypeIds1" value="1">Type 1        
    <input type="checkbox" id="ChkBoxType3" name="requestTypeIds3" value="3">Type 3
</div>

Thank you very much!

like image 640
Tuizi Avatar asked May 16 '11 15:05

Tuizi


1 Answers

validation plugin works according to the name attribute and not id. try changing the name attribute on your input.

like image 137
J. Ed Avatar answered Oct 01 '22 22:10

J. Ed