Saorikido
Saorikido

Reputation: 2290

Jquery validate exception - Uncaught TypeError: Cannot call method 'call' of undefined

Very simple requirement, validate the field whether a positive number or not.

please refer to the js fiddle

http://jsfiddle.net/DJMmm/5/

HTML CODE

<form id="new_leavetype_form" action = "<%=path %>/admin/create.go">

     <input name="default_days" id="default_days_id" type="text"  />      
     <button id="submit_button" type="button">Submit</button>

</form>

JS CODE

$().ready(function(){
    $("#new_leavetype_form").validate({
        rules:{
            default_days: { number: true, required:true, PositiveNumber:true }
        }
    });

    $("#submit_button").click(function(){
        $("#new_leavetype_form").submit();
    });

})

Question

if fill letter(s) like 'abc' into the filed, while the filed lost focus, the validation was fired properly, however if the input is a number will cause the exception: 'Cannot call method 'call' of undefined '

I really don't know what caused this exception, please help, thank you.

Upvotes: 0

Views: 2882

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388316

There is no validation rule with name PositiveNumber.

Either you need to create a new rule or you can set the min rule to achieve the dame

$("#new_leavetype_form").validate({
    rules: {
        default_days: {
            number: true,
            required: true,
            min: 0
        }
    }
});

Demo: Fiddle

Upvotes: 2

Related Questions