Skip to content

Commit

Permalink
fix: fix side-effect of jQuery .filter() in Abide.addA11yAttributes
Browse files Browse the repository at this point in the history
Prevent jQuery `.filter()` to mutate the context object.
  • Loading branch information
ncoden committed Jan 22, 2018
1 parent edf21d2 commit c6a6906
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions js/foundation.abide.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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') {
Expand All @@ -242,7 +242,7 @@ class Abide extends Plugin {
const $label = $(label);
if (typeof $label.attr('for') === 'undefined')
$label.attr('for', elemId);
});
}).end();
}
}

Expand Down

0 comments on commit c6a6906

Please sign in to comment.