From a2b5abce7a1ccc1c7171dfc4ded71011b937d014 Mon Sep 17 00:00:00 2001 From: Dariusz Szut Date: Wed, 23 Oct 2024 15:05:42 +0200 Subject: [PATCH] IBX-9137: Fixed disabled state on translate button when no languages available --- .../scripts/admin.location.add.translation.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/bundle/Resources/public/js/scripts/admin.location.add.translation.js b/src/bundle/Resources/public/js/scripts/admin.location.add.translation.js index 683db9ef1c..457e79e379 100644 --- a/src/bundle/Resources/public/js/scripts/admin.location.add.translation.js +++ b/src/bundle/Resources/public/js/scripts/admin.location.add.translation.js @@ -1,17 +1,15 @@ (function (global, doc) { const SELECTOR_MODAL = '.ibexa-modal'; + const toggleBtnDisabledState = (select) => { + const modal = select.closest(SELECTOR_MODAL); + const buttonCreate = modal.querySelector('.ibexa-btn--create-translation'); + + buttonCreate.toggleAttribute('disabled', !select.value); + }; doc.querySelectorAll('.ibexa-translation__language-wrapper--language').forEach((select) => { - select.addEventListener( - 'change', - (event) => { - const modal = event.target.closest(SELECTOR_MODAL); - const buttonCreate = modal.querySelector('.ibexa-btn--create-translation'); - const method = event.target.value ? 'removeAttribute' : 'setAttribute'; + toggleBtnDisabledState(select); - buttonCreate[method]('disabled', true); - }, - false, - ); + select.addEventListener('change', toggleBtnDisabledState, false); }); })(window, window.document);