From d961613058cec3e7b1ee184643b483dc92170e54 Mon Sep 17 00:00:00 2001 From: James Addison <55152140+jayaddison@users.noreply.github.com> Date: Tue, 25 Oct 2022 02:02:30 +0100 Subject: [PATCH] Unselect events: cache lookup key fix (#6179) * During selection and unselection events, retrieve cached item data using the original 'option' element as the cache lookup key instead of the event target * Fixup: only use 'option' element as cache lookup key during unselection -- not selection -- events * Narrow down 'option' element query to find the unselected item by value * Consistency: prefer jQuery.find...each pattern as used elsewhere in the codebase * Lint fixup: fit within line length limits * Use equality checks instead of jQuery/CSS selector attribute matching to filter relevant 'option' elements --- src/js/select2/data/select.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/js/select2/data/select.js b/src/js/select2/data/select.js index f4eec511cd..2c21dec580 100644 --- a/src/js/select2/data/select.js +++ b/src/js/select2/data/select.js @@ -114,7 +114,12 @@ define([ }); container.on('unselect', function (params) { - self.unselect(params.data); + container.$element.find('option').each(function () { + if ($(this).val() == params.data.id) { + var data = Utils.GetData(this, 'data'); + self.unselect(data); + } + }); }); };