Skip to content

Commit

Permalink
maint(core utils): Modernize code for findRelatives.
Browse files Browse the repository at this point in the history
  • Loading branch information
thet committed Nov 5, 2023
1 parent 7cfd08a commit 8bba671
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,18 +494,22 @@ function parseLength(length, reference_length = null) {

// Return a jQuery object with elements related to an input element.
function findRelatives(el) {
var $el = $(el),
$relatives = $(el),
$label = $();
const $el = $(el);
let $relatives = $(el);
let $label = $();

$relatives = $relatives.add($el.closest("label"));
$relatives = $relatives.add($el.closest("fieldset"));

if (el.id) $label = $("label[for='" + el.id + "']");
if (el.id) {
$label = $(`label[for="${el.id}"]`);
}
if (!$label.length) {
var $form = $el.closest("form");
if (!$form.length) $form = $(document.body);
$label = $form.find("label[for='" + el.name + "']");
let $form = $el.closest("form");
if (!$form.length) {
$form = $(document.body);
}
$label = $form.find(`label[for="${el.name}"]`);
}
$relatives = $relatives.add($label);
return $relatives;
Expand Down

0 comments on commit 8bba671

Please sign in to comment.