garygreen / dominar

Lightweight bootstrap validator inspired by Laravel
http://garygreen.github.io/dominar/
22 stars 4 forks source link

Don't revalidate if already validated and field value hasn't changed. #2

Open garygreen opened 9 years ago

garygreen commented 9 years ago

Especially useful for remoteRule so it won't fire new requests if value was already validated and hasn't changed.

RichAyotte commented 9 years ago

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();
});
vlascik commented 8 years ago

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?