From d9994233d3c904c1fc0cdb1d5a4a8e99fd27512a Mon Sep 17 00:00:00 2001 From: jk Date: Thu, 10 Dec 2015 20:25:28 +0100 Subject: [PATCH] adds support validator through data-abide-validator and validatorLib fixes equalto --- js/foundation.abide.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) 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 -- 2.47.2