From: Chris Oyler Date: Tue, 22 Dec 2015 18:41:55 +0000 (-0800) Subject: reverts to a previous version of new abide, and adds back the custom regex pattern... X-Git-Tag: v6.1.0~4^2^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4217ed066122a9038733416677bb7db8a4ddc126;p=thirdparty%2Ffoundation%2Ffoundation-sites.git reverts to a previous version of new abide, and adds back the custom regex pattern testing throught the pattern attribute. Will update radio and checkbox groups in the future --- diff --git a/js/foundation.abide.js b/js/foundation.abide.js index ff24f711b..3214f5178 100644 --- a/js/foundation.abide.js +++ b/js/foundation.abide.js @@ -111,24 +111,10 @@ * @private */ Abide.prototype._init = function(){ - this.$inputs = this.$element.find('input, textarea, select').not('[data-abide-ignore], :radio, :checkbox'); - this.$ticks = this.$element.find(':radio, :checkbox'); + this.$inputs = this.$element.find('input, textarea, select').not('[data-abide-ignore]'); - if(this.$ticks.length) this._checkTicks() - this.radioRequiredGroups(); this._events(); }; - Abide.prototype._checkTicks = function(){ - var names = []; - this.$ticks.each(function(){ - if(this.name && names.indexOf(this.name) === -1) names.push(this.name); - }) - console.log(names); - // this.$sets = this.$ticks.map(function(){ - // var box = $(this); - // return $('[name=]') - // }) - }; /** * Initializes events for Abide. @@ -275,7 +261,6 @@ case 'radio': validated = this.validateRadio($el.attr('name')); - clearRequire = validated; break; case 'checkbox': @@ -320,12 +305,6 @@ var acc = [], _this = this; - if(this.$ticks.length){ - // this.validateTicks(); - // this.$ticks.each(function(){ - // acc.push(_this.validateTicks($(this))); - // }); - } this.$inputs.each(function(){ acc.push(_this.validateInput($(this))); }); @@ -339,53 +318,42 @@ * @event Abide#formvalid * @event Abide#forminvalid */ - .trigger((noError ? 'valid' : 'invalid') + '.zf.abide', [this.$element]); + .trigger((noError ? 'formvalid' : 'forminvalid') + '.zf.abide', [this.$element]); return noError; }; - Abide.prototype.validateTicks = function($el, name){ - // $el = $el === undefined ? this.$element : $el; - // var group = $el.find('[name="'+name+'"]'); - // if - }; /** * Determines whether or a not a text input is valid based on the pattern specified in the attribute. If no matching pattern is found, returns true. * @param {Object} $el - jQuery object to validate, should be a text input HTML element * @param {String} pattern - string value of one of the RegEx patterns in Abide.options.patterns * @returns {Boolean} Boolean value depends on whether or not the input value matches the pattern specified */ - Abide.prototype.validateText = function($el, pattern){ - // pattern = pattern ? pattern : $el.attr('pattern') ? $el.attr('pattern') : $el.attr('type'); - pattern = (pattern || $el.attr('pattern') || $el.attr('type')); - var inputText = $el.val(); - - return inputText.length ?//if text, check if the pattern exists, if so, test it, if no text or no pattern, return true. - this.options.patterns.hasOwnProperty(pattern) ? this.options.patterns[pattern].test(inputText) : - pattern && pattern !== $el.attr('type') ? new RegExp(pattern).test(inputText) : true : true; - }; - /** + Abide.prototype.validateText = function($el, pattern){ + // pattern = pattern ? pattern : $el.attr('pattern') ? $el.attr('pattern') : $el.attr('type'); + pattern = (pattern || $el.attr('pattern') || $el.attr('type')); + var inputText = $el.val(); + + return inputText.length ?//if text, check if the pattern exists, if so, test it, if no text or no pattern, return true. + this.options.patterns.hasOwnProperty(pattern) ? this.options.patterns[pattern].test(inputText) : + pattern && pattern !== $el.attr('type') ? new RegExp(pattern).test(inputText) : true : true; + }; /** * Determines whether or a not a radio input is valid based on whether or not it is required and selected * @param {String} groupName - A string that specifies the name of a radio button group * @returns {Boolean} Boolean value depends on whether or not at least one radio input has been selected (if it's required) */ Abide.prototype.validateRadio = function(groupName){ - if(this.radioRequiredGroups.indexOf(groupName) === -1) return true; var $group = this.$element.find(':radio[name="' + groupName + '"]'), - labels = [], - counter = false, + counter = [], _this = this; + $group.each(function(){ - labels.push(_this.findLabel($(this))); - if(this.checked){ - counter = true; - } + var rdio = $(this), + clear = _this.requiredCheck(rdio); + counter.push(clear); + if(clear) _this.removeErrorClasses(rdio); }); - if (counter) { - for(var i = 0, len = labels.length; i < len; i++){ - _this.removeErrorClasses(labels[i]); - }; - }; - return counter; + + return counter.indexOf(false) === -1; }; /** * Determines if a selected input passes a custom validation function. Multiple validations can be used, if passed to the element with `data-validator="foo bar baz"` in a space separated listed. @@ -421,18 +389,6 @@ */ $form.trigger('formreset.zf.abide', [$form]); }; - /** - * Build radioRequiredGroups for validateRadio required check - */ - Abide.prototype.radioRequiredGroups = function() { - var _this = this; - _this.radioRequiredGroups = []; - - _this.$inputs.filter(':radio').each(function(){ - console.log(this); - this.required && _this.radioRequiredGroups.indexOf(this.name)===-1?_this.radioRequiredGroups.push(this.name):false; - }); - }; /** * Destroys an instance of Abide. * Removes error styles and classes from elements, without resetting their values.