]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
fix bug where every valid element after an invalid was marked as invalid 5738/head
authorChristian Seel <cs@chsmedien.de>
Thu, 4 Sep 2014 06:37:30 +0000 (08:37 +0200)
committerChristian Seel <cs@chsmedien.de>
Thu, 4 Sep 2014 06:37:30 +0000 (08:37 +0200)
There is a bug where every valid element after an invalid element was marked/styled as invalid due the fact that the `validations` array was global and always included a `false` when a previous element was invalid.

js/foundation/foundation.abide.js

index 45f04a82a357d63d3a7cba9ef85139c57fbdf21b..b4349210a770ce56bdb710f3de9a8349deab8b23 100644 (file)
             is_radio = el.type === "radio",
             is_checkbox = el.type === "checkbox",
             label = this.S('label[for="' + el.getAttribute('id') + '"]'),
-            valid_length = (required) ? (el.value.length > 0) : true;
+            valid_length = (required) ? (el.value.length > 0) : true,
+            el_validations = [];
 
         var parent, valid;
 
 
         if (validator) {
           valid = this.settings.validators[validator].apply(this, [el, required, parent]);
-          validations.push(valid);
+          el_validations.push(valid);
         }
 
         if (is_radio && required) {
-          validations.push(this.valid_radio(el, required));
+          el_validations.push(this.valid_radio(el, required));
         } else if (is_checkbox && required) {
-          validations.push(this.valid_checkbox(el, required));
+          el_validations.push(this.valid_checkbox(el, required));
         } else {
 
           if (el_patterns[i][1].test(value) && valid_length ||
             !required && el.value.length < 1 || $(el).attr('disabled')) {
-            validations.push(true);
+            el_validations.push(true);
           } else {
-            validations.push(false);
+            el_validations.push(false);
           }
 
-          validations = [validations.every(function(valid){return valid;})];
+          el_validations = [el_validations.every(function(valid){return valid;})];
 
-          if(validations[0]){
+          if(el_validations[0]){
             this.S(el).removeAttr(this.invalid_attr);
             el.setAttribute('aria-invalid', 'false');
             el.removeAttribute('aria-describedby');
             }
             $(el).triggerHandler('invalid');
           }
-
+          validations.push(el_validations[0]);
         }
       }
-
+      validations = [validations.every(function(valid){return valid;})];
       return validations;
     },