From be0af4c44764a9a2e62545aaab6638b4e901b508 Mon Sep 17 00:00:00 2001 From: Hendra Nicholas Date: Mon, 8 Aug 2022 10:29:17 +0700 Subject: [PATCH 1/2] Fixed select2 dropdown autofocus on open --- app/assets/javascripts/spree/backend/spree-select2.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/assets/javascripts/spree/backend/spree-select2.js b/app/assets/javascripts/spree/backend/spree-select2.js index fb0e67283f..e62e26c973 100644 --- a/app/assets/javascripts/spree/backend/spree-select2.js +++ b/app/assets/javascripts/spree/backend/spree-select2.js @@ -17,6 +17,12 @@ document.addEventListener("spree:load", function() { placeholder: Spree.translations.select_an_option, allowClear: true }) + + if(jQuery().jquery === '3.6.0') { + $(document).on('select2:open', () => { + document.querySelector('.select2-search__field').focus() + }); + } }) $.fn.addSelect2Options = function (data) { From c1af95f121bd7e58347bd9b6792b95b86d8a74a0 Mon Sep 17 00:00:00 2001 From: Hendra Nicholas Date: Mon, 29 Aug 2022 01:24:46 +0700 Subject: [PATCH 2/2] Replaced jQuery check version with broader check --- app/assets/javascripts/spree/backend/spree-select2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/spree/backend/spree-select2.js b/app/assets/javascripts/spree/backend/spree-select2.js index e62e26c973..0719c33027 100644 --- a/app/assets/javascripts/spree/backend/spree-select2.js +++ b/app/assets/javascripts/spree/backend/spree-select2.js @@ -18,7 +18,7 @@ document.addEventListener("spree:load", function() { allowClear: true }) - if(jQuery().jquery === '3.6.0') { + if(jQuery().jquery >= '3.6.0') { $(document).on('select2:open', () => { document.querySelector('.select2-search__field').focus() });