From ec0918e28458afce85905d89163ca7bf4b79044f Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Mon, 6 Jan 2020 21:19:12 +1100 Subject: [PATCH] Fixes removal of first item from taglist Tested #4867 but it broke the use of pressing TAB after entering a tag to lock it in. This seems to retain that functionality and yet still fix the issue Replaces #4867 --- modules/system/assets/ui/js/select.js | 9 +++++++++ modules/system/assets/ui/storm-min.js | 6 +++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/system/assets/ui/js/select.js b/modules/system/assets/ui/js/select.js index a7c6c5190..7fa1c9732 100644 --- a/modules/system/assets/ui/js/select.js +++ b/modules/system/assets/ui/js/select.js @@ -124,7 +124,16 @@ extraOptions.selectOnClose = true extraOptions.closeOnSelect = false + var unselecting = false + $element.on('select2:unselect', function() { + unselecting = true + }) + $element.on('select2:open', function() { + unselecting = false + }) + $element.on('select2:closing', function() { + if (unselecting) return $('.select2-dropdown.select-no-dropdown:first .select2-results__option--highlighted').removeClass('select2-results__option--highlighted') $('.select2-dropdown.select-no-dropdown:first .select2-results__option:first').addClass('select2-results__option--highlighted') }) diff --git a/modules/system/assets/ui/storm-min.js b/modules/system/assets/ui/storm-min.js index 5b38f7951..1f14ef3fd 100644 --- a/modules/system/assets/ui/storm-min.js +++ b/modules/system/assets/ui/storm-min.js @@ -3526,7 +3526,11 @@ if(separators){extraOptions.tags=true extraOptions.tokenSeparators=separators.split('|') if($element.hasClass('select-no-dropdown')){extraOptions.selectOnClose=true extraOptions.closeOnSelect=false -$element.on('select2:closing',function(){$('.select2-dropdown.select-no-dropdown:first .select2-results__option--highlighted').removeClass('select2-results__option--highlighted') +var unselecting=false +$element.on('select2:unselect',function(){unselecting=true}) +$element.on('select2:open',function(){unselecting=false}) +$element.on('select2:closing',function(){if(unselecting)return +$('.select2-dropdown.select-no-dropdown:first .select2-results__option--highlighted').removeClass('select2-results__option--highlighted') $('.select2-dropdown.select-no-dropdown:first .select2-results__option:first').addClass('select2-results__option--highlighted')})}} var placeholder=$element.data('placeholder') if(placeholder){extraOptions.placeholder=placeholder