color : /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/
},
validators: {
- equalTo: function (el, required, parent) {
- var from = document.getElementById(el.getAttribute(this.add_namespace('data-equalto'))).value,
- to = el.value,
+ equalTo: function ($el, required, parent) {
+ var from = $('#'+$el.attr('data-equalto')).val(),
+ to = $el.val(),
valid = (from === to);
return valid;
*/
Abide.prototype.validateText = function($el) {
var self = this,
- valid = false,
+ valid = true,
patternLib = this.options.patterns,
- inputText = $($el).val(),
+ inputText = $el.val(),
elTypeProperty = patternLib.hasOwnProperty($el[0].type)?patternLib[$el[0].type]:false,
- elPattern = $($el).attr('pattern'),
- elDataPattern = $($el).data('pattern'),
- pattern = false;
+ elPattern = $el.attr('pattern'),
+ elDataPattern = $el.attr('data-pattern'),
+ pattern = false,
+ validatorLib = this.options.validators,
+ validatorOwnProperty = $el.attr('data-abide-validator'),
+ validator = validatorLib.hasOwnProperty(validatorOwnProperty)?validatorLib[validatorOwnProperty]:false;
// maybe have a different way of parsing this bc people might use type
if (elDataPattern && elDataPattern.length > 0) {
// if there's no value, then return true
// since required check has already been done
if (inputText.length === 0) {
- return true;
+ valid = true;
}
else {
- if ((pattern && inputText.match(pattern)) || !pattern) {
- return true;
+ if ((pattern && inputText.match(pattern))) {
+ valid = true;
+ }else if(pattern){
+ valid = false;
}
- else {
- return false;
+ if(typeof validator === 'function') {
+ valid = validator($el,$el.attr('required'),$el.parent());
}
}
+ return valid;
};
/**
* Determines whether or a not a radio input is valid based on whether or not it is required and selected