coure2011
coure2011

Reputation: 42454

Uncaught TypeError: Object #<error> has no method 'call'

Using the jquery validate plugin, I want to show/hide error only when the element's blur event is called, dont want to show error message as you type. To fix this I tried

$('#form').validate({
    onfocusout: true,
    onkeyup: false
});

but as soon I click outside any element it throws error

Uncaught TypeError: Object #<error> has no method 'call' 

Upvotes: 1

Views: 2901

Answers (2)

Sparky
Sparky

Reputation: 98738

As already pointed out by Sudhir, you've misspelled the onfocusout option.

Additionally, the onfocusout and onkeyup options are already enabled by default in this plugin.

You only have two choices...

1) If you want to disable onfocusout or onkeyup, you would set them to false...

$('#form').validate({
    onfocusout: false, // disable validation on blur
    onkeyup: false     // disable validation on key-up
});

2) If you want to modify the default behavior of onfocusout or onkeyup, you would set them to your custom function...

$('#form').validate({
    onfocusout: function(element, event) {
        // your custom callback function for blur event
    },
    onkeyup: function(element, event) {
        // your custom callback function for key-up event
    }
});

Otherwise, if you simply want the default behavior of the onfocusout or onkeyup options, leave them out of the .validate() call entirely. As per documentation, setting these to true "is not a valid value" and will break the plugin.

$('#form').validate({
    // onfocusout: true, // <- remove this line, true value is not valid
    // onkeyup: true     // <- remove this line, true value is not valid
});

Documentation:

onfocusout
Type: Boolean or Function()
Validate elements (except checkboxes/radio buttons) on blur. If nothing is entered, all rules are skipped, except when the field was already marked as invalid. Set to a Function to decide for yourself when to run validation. A boolean true is not a valid value.


onkeyup
Type: Boolean or Function()
Validate elements on keyup. As long as the field is not marked as invalid, nothing happens. Otherwise, all rules are checked on each key up event. Set to false to disable. Set to a Function to decide for yourself when to run validation. A boolean true is not a valid value.

Upvotes: 1

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

its onfocusout not onfoucusout, change to:

$('#form').validate({
    onfocusout: function(element) { $(element).valid(); },
    onkeyup: function(element) { $(element).valid(); }
});

Upvotes: 4

Related Questions