From d0624167d69acfc6a71ca022410bce1f212315eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ste=CC=A8pien=CC=81?= Date: Mon, 9 Oct 2023 23:48:21 +0200 Subject: [PATCH] form select link --- _dev/js/theme/components/useThemeForm.js | 19 +++++++++++++++++-- _dev/js/theme/index.js | 4 ---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/_dev/js/theme/components/useThemeForm.js b/_dev/js/theme/components/useThemeForm.js index 1a2ca365..4e58f073 100644 --- a/_dev/js/theme/components/useThemeForm.js +++ b/_dev/js/theme/components/useThemeForm.js @@ -1,4 +1,5 @@ import { each } from '../utils/DOMHelpers'; +import $ from "jquery"; const supportedValidity = () => { const input = document.createElement('input'); @@ -88,10 +89,24 @@ const useThemeForm = ( validationFormSelector = '.js-needs-validation', passwordToggleSelector = '[data-action="show-password"]', ) => { + const DOM_SELECTORS = { + SELECT_LINK: '.js-select-link', + } + + const handleSelectChange = (event) => { + const target = event.target; + + if (target) { + window.location.href = target.value; + } + } const init = () => { - each(document.querySelectorAll(passwordToggleSelector), togglePasswordVisibility) - each(document.querySelectorAll(validationFormSelector), formValidation) + each(document.querySelectorAll(passwordToggleSelector), togglePasswordVisibility); + each(document.querySelectorAll(validationFormSelector), formValidation); + each(document.querySelectorAll(DOM_SELECTORS.SELECT_LINK), (select) => { + select.addEventListener('change', handleSelectChange); + }); } return { diff --git a/_dev/js/theme/index.js b/_dev/js/theme/index.js index b7cc612d..9072b7e1 100644 --- a/_dev/js/theme/index.js +++ b/_dev/js/theme/index.js @@ -41,8 +41,4 @@ $(() => { initForm(); bsCustomFileInput.init(); usePasswordPolicy('.field-password-policy'); - - $('.js-select-link').on('change', ({ target }) => { - window.location.href = $(target).val(); - }); });