dominar
dominar copied to clipboard
Don't revalidate if already validated and field value hasn't changed.
Especially useful for remoteRule
so it won't fire new requests if value was already validated and hasn't changed.
Here's a workaround. Let me know what you think about the strategy and I might be able to send you a PR, without the dependence on jquery-aop of course.
Oct 23: Updated workaround
$('form').bind('dominar.init-field', function(event) {
event.dominarField.$field.on('keyup paste', function() {
event.dominarField.$container.removeClass('has-success');
});
});
$.aop.around({
target: validator.DominarField
, method: 'validate'
}, function(invocation) {
if (this.$container.hasClass('has-success')) {
if (typeof invocation.arguments[0] === 'function') { // passes
return invocation.arguments[0]()
};
}
return invocation.proceed();
});
This would be most helpful, remote requests are firing several times needlessly, but maybe just store the last validated value and validation result for each field, and compare them before validating again, instead of removing classes?