From c0258d59e5907231d0ad2d66a288ccfb747abc31 Mon Sep 17 00:00:00 2001 From: nmandrescu <17854915+nmandrescu@users.noreply.github.com> Date: Wed, 1 Jun 2022 20:37:32 +0300 Subject: [PATCH] Fixes #445 --- .../styles/assets/js/select2/select2.full.js | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/styles/assets/js/select2/select2.full.js b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/styles/assets/js/select2/select2.full.js index d756fb4b..155d7d75 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/styles/assets/js/select2/select2.full.js +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/styles/assets/js/select2/select2.full.js @@ -780,9 +780,9 @@ S2.define('select2/utils',[ var id = 0; Utils.GetUniqueElementId = function (element) { - // Get a unique element Id. If element has no id, - // creates a new unique number, stores it in the id - // attribute and returns the new id. + // Get a unique element Id. If element has no id, + // creates a new unique number, stores it in the id + // attribute and returns the new id. // If an id already exists, it simply returns it. var select2Id = element.getAttribute('data-select2-id'); @@ -801,7 +801,7 @@ S2.define('select2/utils',[ Utils.StoreData = function (element, name, value) { // Stores an item in the cache for a specified element. - // name is the cache key. + // name is the cache key. var id = Utils.GetUniqueElementId(element); if (!Utils.__cache[id]) { Utils.__cache[id] = {}; @@ -812,19 +812,19 @@ S2.define('select2/utils',[ Utils.GetData = function (element, name) { // Retrieves a value from the cache by its key (name) - // name is optional. If no name specified, return + // name is optional. If no name specified, return // all cache items for the specified element. // and for a specified element. var id = Utils.GetUniqueElementId(element); if (name) { if (Utils.__cache[id]) { - return Utils.__cache[id][name] != null ? + return Utils.__cache[id][name] != null ? Utils.__cache[id][name]: $(element).data(name); // Fallback to HTML5 data attribs. } return $(element).data(name); // Fallback to HTML5 data attribs. } else { - return Utils.__cache[id]; + return Utils.__cache[id]; } }; @@ -4077,6 +4077,17 @@ S2.define('select2/dropdown/search',[ }); }; + // see https://github.com/select2/select2/issues/5993 + // using this workaround https://github.com/select2/select2/issues/5993#issuecomment-1050841204 + $(document).on('select2:open', () => { + let allFound = document.querySelectorAll('.select2-container--open .select2-search__field'); + $(this).one('mouseup keyup', () => { + setTimeout(() => { + allFound[allFound.length - 1].focus(); + }, 0); + }); + }); + Search.prototype.handleSearch = function (evt) { if (!this._keyUpPrevented) { var input = this.$search.val(); @@ -5102,7 +5113,7 @@ S2.define('select2/options',[ $e.attr('ajax--url', Utils.GetData($e[0], 'ajaxUrl')); Utils.StoreData($e[0], 'ajax-Url', Utils.GetData($e[0], 'ajaxUrl')); - + } var dataset = {};