]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
fixes radio requiredCheck 7633/head
authorjk <j.koehler@modulingo.de>
Sat, 19 Dec 2015 21:21:02 +0000 (22:21 +0100)
committerjk <j.koehler@modulingo.de>
Sat, 19 Dec 2015 21:21:02 +0000 (22:21 +0100)
as required attribute is on one radio element group [name] is matched and error applied to group [name]

js/foundation.abide.js

index d2802ea28e2dd3590e34bdf741134a7e2c820dcb..527291da726f4ab99164bb3ac6733f00fdea50ef 100644 (file)
   Abide.prototype._init = function(){
     this.$inputs = this.$element.find('input, textarea, select').not('[data-abide-ignore]');
 
+    this.radioRequiredGroups();
     this._events();
   };
 
 
       case 'radio':
         validated = this.validateRadio($el.attr('name'));
+        clearRequire = validated;
         break;
 
       case 'checkbox':
    * @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 + '"]'),
-        counter = [],
-        _this = this;
-
+        labels = [],
+        counter = false,
+        self = this;
     $group.each(function(){
-      var rdio = $(this),
-          clear = _this.requiredCheck(rdio);
-      counter.push(clear);
-      if(clear) _this.removeErrorClasses(rdio);
+      labels.push(self.findLabel($(this)));
+      if(this.checked){
+        counter = true;
+      }
     });
-
-    return counter.indexOf(false) === -1;
+    if (counter) {
+      for(var i = 0, len = labels.length; i < len; i++){
+        self.removeErrorClasses(labels[i]);
+      };
+    };
+    return counter;
   };
   /**
    * 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.
      */
     $form.trigger('formreset.zf.abide', [$form]);
   };
+  /**
+   * Build radioRequiredGroups for validateRadio required check
+   */
+  Abide.prototype.radioRequiredGroups = function() {
+    var self = this;
+    self.radioRequiredGroups = [];
+
+    self.$inputs.filter(':radio').each(function(){
+      this.required && self.radioRequiredGroups.indexOf(this.name)===-1?self.radioRequiredGroups.push(this.name):false;
+    });
+  };
   /**
    * Destroys an instance of Abide.
    * Removes error styles and classes from elements, without resetting their values.