From: jk Date: Thu, 10 Dec 2015 19:25:28 +0000 (+0100) Subject: adds support validator through data-abide-validator and validatorLib fixes equalto X-Git-Tag: v6.1.0~4^2^2~17^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F7470%2Fhead;p=thirdparty%2Ffoundation%2Ffoundation-sites.git adds support validator through data-abide-validator and validatorLib fixes equalto --- diff --git a/js/foundation.abide.js b/js/foundation.abide.js index 2b6053cea..e4a601a75 100644 --- a/js/foundation.abide.js +++ b/js/foundation.abide.js @@ -62,9 +62,9 @@ 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; @@ -305,13 +305,16 @@ */ 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) { @@ -325,16 +328,19 @@ // 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