From: Chris Oyler Date: Tue, 22 Dec 2015 18:31:08 +0000 (-0800) Subject: start of new path to validate radio/checkbox groups based on a common parent or name... X-Git-Tag: v6.1.0~4^2^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d4608e837d7d66c8f318308dabee4e44dd8baf7;p=thirdparty%2Ffoundation%2Ffoundation-sites.git start of new path to validate radio/checkbox groups based on a common parent or name attribute. Stashing in separate branch for future implementation --- diff --git a/js/foundation.abide.js b/js/foundation.abide.js index 846636ca4..ff24f711b 100644 --- a/js/foundation.abide.js +++ b/js/foundation.abide.js @@ -111,11 +111,24 @@ * @private */ Abide.prototype._init = function(){ - this.$inputs = this.$element.find('input, textarea, select').not('[data-abide-ignore]'); + this.$inputs = this.$element.find('input, textarea, select').not('[data-abide-ignore], :radio, :checkbox'); + this.$ticks = this.$element.find(':radio, :checkbox'); + 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. @@ -307,6 +320,12 @@ 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))); }); @@ -324,6 +343,11 @@ 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 @@ -337,7 +361,7 @@ 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; + 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 @@ -345,20 +369,20 @@ * @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; + if(this.radioRequiredGroups.indexOf(groupName) === -1) return true; var $group = this.$element.find(':radio[name="' + groupName + '"]'), labels = [], counter = false, - self = this; + _this = this; $group.each(function(){ - labels.push(self.findLabel($(this))); + labels.push(_this.findLabel($(this))); if(this.checked){ counter = true; } }); if (counter) { for(var i = 0, len = labels.length; i < len; i++){ - self.removeErrorClasses(labels[i]); + _this.removeErrorClasses(labels[i]); }; }; return counter; @@ -401,11 +425,12 @@ * Build radioRequiredGroups for validateRadio required check */ Abide.prototype.radioRequiredGroups = function() { - var self = this; - self.radioRequiredGroups = []; + var _this = this; + _this.radioRequiredGroups = []; - self.$inputs.filter(':radio').each(function(){ - this.required && self.radioRequiredGroups.indexOf(this.name)===-1?self.radioRequiredGroups.push(this.name):false; + _this.$inputs.filter(':radio').each(function(){ + console.log(this); + this.required && _this.radioRequiredGroups.indexOf(this.name)===-1?_this.radioRequiredGroups.push(this.name):false; }); }; /**