diff options
author | Lauri Eskola <lauri.eskola@acquia.com> | 2022-01-17 18:08:33 +0200 |
---|---|---|
committer | Lauri Eskola <lauri.eskola@acquia.com> | 2022-01-17 18:08:33 +0200 |
commit | 68081082c0605192b76850d96ae8a058c256ecca (patch) | |
tree | 51c2b7ea3ef5c6e229a308e4a4922688372d83a8 /core/misc/form.js | |
parent | 440bcc0551fd41ed2197808b38a1c42524993899 (diff) | |
download | drupal-68081082c0605192b76850d96ae8a058c256ecca.tar.gz drupal-68081082c0605192b76850d96ae8a058c256ecca.zip |
Issue #3239134 by hooroomoo, bnjmnm, yogeshmpawar, nod_, Theresa.Grannum, larowlan: Refactor (if feasible) uses of the jQuery val function to use VanillaJS
Diffstat (limited to 'core/misc/form.js')
-rw-r--r-- | core/misc/form.js | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/core/misc/form.js b/core/misc/form.js index c51425ea753..ea5f8f50e60 100644 --- a/core/misc/form.js +++ b/core/misc/form.js @@ -105,10 +105,18 @@ userInfo.forEach(info => { const $element = $forms.find(`[name=${info}]`); const browserData = localStorage.getItem(`Drupal.visitor.${info}`); - const emptyOrDefault = $element.val() === '' || $element.attr('data-drupal-default-value') === $element.val(); - if ($element.length && emptyOrDefault && browserData) { - $element.val(browserData); + if (!$element.length) { + return; + } + + const emptyValue = $element[0].value === ''; + const defaultValue = $element.attr('data-drupal-default-value') === $element[0].value; + + if (browserData && (emptyValue || defaultValue)) { + $element.each(function (index, item) { + item.value = browserData; + }); } }); } @@ -118,7 +126,7 @@ const $element = $forms.find(`[name=${info}]`); if ($element.length) { - localStorage.setItem(`Drupal.visitor.${info}`, $element.val()); + localStorage.setItem(`Drupal.visitor.${info}`, $element[0].value); } }); }); |