]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
fix: fix side-effect of jQuery .filter() in Abide.addA11yAttributes
authorNicolas Coden <nicolas@ncoden.fr>
Mon, 22 Jan 2018 22:25:36 +0000 (23:25 +0100)
committerNicolas Coden <nicolas@ncoden.fr>
Mon, 22 Jan 2018 22:25:36 +0000 (23:25 +0100)
Prevent jQuery `.filter()` to mutate the context object.

js/foundation.abide.js

index ab3bce0c171e3e18dd6b33f7e44ca848a1655701..28ef56d47083468c95d46b71320933429319957f 100644 (file)
@@ -213,8 +213,8 @@ class Abide extends Plugin {
    */
   addA11yAttributes($el) {
     let $errors = this.findFormError($el);
-    let $labels = $errors.filter('label');
-    let $error = $errors.first();
+    let $labels = $errors.filter('label').end();
+    let $error = $errors.first().end();
     if (!$errors.length) return;
 
     // Set [aria-describedby] on the input toward the first form error if it is not set
@@ -229,7 +229,7 @@ class Abide extends Plugin {
       $el.attr('aria-describedby', errorId);
     }
 
-    if ($labels.filter('[for]').length < $labels.length) {
+    if ($labels.filter('[for]').end().length < $labels.length) {
       // Get the input ID or create one
       let elemId = $el.attr('id');
       if (typeof elemId === 'undefined') {
@@ -242,7 +242,7 @@ class Abide extends Plugin {
         const $label = $(label);
         if (typeof $label.attr('for') === 'undefined')
           $label.attr('for', elemId);
-      });
+      }).end();
     }
   }