'How to stop update on keyup if the error message is the same with Jquery validate
Whenever I type in Jquery validated field on max and min number of letters, I get a refresh of messages even though the error is the same. How do I prevent that so it is less irritating for the users?
The code is
validations = {
'rules':{
'code': {
'minlength': 9,
'maxlength': 9
},
},
'messages': {
'code': {
'minlength': 'Must be 9 digits',
'maxlength': 'Must be 9 digits'
},
}
}
I have tried to use showerror(), and check whether the error list is the same, but I can't prevent the previous error messages from disappearing.
showErrors: function(errorMap, errorList) {
if(typeof prev_error_map != "undefined"){
if (!_.isEqual(prev_error_map, errorMap)) {
this.defaultShowErrors();
prev_error_map = errorMap;
}
}else{
this.defaultShowErrors();
prev_error_map = errorMap;
}
}
Solution 1:[1]
So I figured out my mistake. Instead of doing
'minlength': x,
'maxlength': y
I should have done
'rangelength': [x,y]
This way, the length is only checked once and potential updates are avoided.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DrKeith |
