I'm writing a method that generate the string selector to use to bind an input event on an element.
I'm facing to a little problem, for now my code works but not perfectly.
If not_validated = true then it doesn't matter the value of valid/invalid because my select will select them anyway. I'm looking for a way to exclude the elements that have some classes. See the TODO in the source code. Probably something with ^ or ! but I only know the ways that use methods such as $.hasClass and so on.
FormValidator.prototype.defaultOptions = {
// Performs live validation, on value change.
live: {
not_validated: true,
valid: true,
invalid: true
}
};
// Stuff ...
FormValidator.prototype._generateSelectorOnInput = function() {
var selector = '';
if(this.options.live && this.options.live.not_validated){
selector += '[data-validate]'// TODO: Need to exclude the selector that have INPUT_SUCCESS_CLASS or INPUT_ERROR_CLASS !
}
if(this.options.live && this.options.live.valid){
selector += (selector.length ? ', ' : '') + '[data-validate].' + INPUT_SUCCESS_CLASS
}
if(this.options.live && this.options.live.invalid){
selector += (selector.length ? ', ' : '') + '[data-validate].' + INPUT_ERROR_CLASS
}
return selector;
};
':not()'selector or.not()method may be of interest to you..not(). Usage in your case will be$('[data-validate]').not('.INPUT_SUCCESS_CLASS, .INPUT_ERROR_CLASS')api.jquery.com/not