From d46accfc4f309f5f071cee41ac5bf58092559392 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Tue, 7 Jan 2020 07:04:09 +1100 Subject: [PATCH] Don't force highlight nothing element Causes "Uncaught TypeError: Cannot read property 'element' of undefined at DecoratedClass.SelectOnClose._handleSelectOnClose" Refs #4867 --- modules/system/assets/ui/js/select.js | 6 ++++-- modules/system/assets/ui/storm-min.js | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/system/assets/ui/js/select.js b/modules/system/assets/ui/js/select.js index c7c783052..346f8944f 100644 --- a/modules/system/assets/ui/js/select.js +++ b/modules/system/assets/ui/js/select.js @@ -126,8 +126,10 @@ extraOptions.minimumInputLength = 1 $element.on('select2:closing', function() { - $('.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') + if ($('.select2-dropdown.select-no-dropdown:first .select2-results__option--highlighted').length > 0) { + $('.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 4f963d0d6..85f6c0f77 100644 --- a/modules/system/assets/ui/storm-min.js +++ b/modules/system/assets/ui/storm-min.js @@ -3527,8 +3527,8 @@ extraOptions.tokenSeparators=separators.split('|') if($element.hasClass('select-no-dropdown')){extraOptions.selectOnClose=true extraOptions.closeOnSelect=false extraOptions.minimumInputLength=1 -$element.on('select2:closing',function(){$('.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')})}} +$element.on('select2:closing',function(){if($('.select2-dropdown.select-no-dropdown:first .select2-results__option--highlighted').length>0){$('.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 extraOptions.allowClear=true}