Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
173
rated 0 times [  175] [ 2]  / answers: 1 / hits: 16725  / 11 Years ago, thu, january 30, 2014, 12:00:00

By default, the jQuery validation plugin is attaching validation handlers for focusin, focusout and keyup events.


1 of our validations is making a (synchronous) request to retrieve some data. I want to have that validation triggered only when the form is being submitted and not while the user is typing.


I know this can be modified for the whole form, but that's not what I'm looking for.


Is there a way to dynamically disable keyup validation for 1 element?


Update 1:

I forgot to mention that I'm using unobtrusive validation. So I don't think the answer of @Mario Johnathan is not an option.


Update 2:
I tried the following things ($element is the element on which I want to change the validation behavior):



  1. $element.validate({focusout: false, keyup: false});

  2. $element.keyup(function() { return false; });

  3. $element.off('keyup');

  4. $element.unbind('keyup');


More From » jquery

 Answers
34

I myself was in the same scenario. Below is the code which I used for it.



    $.validator.setDefaults({
onkeyup: function () {
var originalKeyUp = $.validator.defaults.onkeyup;
var customKeyUp = function (element, event) {
if ($(#your_element)[0] === element) {
return false;
}
else {
return originalKeyUp.call(this, element, event);
}
}

return customKeyUp;
}()
});


Here what I have done is handle keyup events for that element so that validator doesn't do anything. For rest all elements the validator will kick into action. But the catch here is that particular element will have no validation on keyup at all.


[#72851] Wednesday, January 29, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marisela

Total Points: 103
Total Questions: 105
Total Answers: 102

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
;