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
This commit is contained in:
Samuel Georges 2020-01-06 21:19:12 +11:00
parent 4a1295162c
commit ec0918e284
2 changed files with 14 additions and 1 deletions

View File

@ -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')
})

View File

@ -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