Skip to content

Commit

Permalink
Unselect events: cache lookup key fix (select2#6179)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jayaddison committed Oct 25, 2022
1 parent 7745d4b commit d961613
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/js/select2/data/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
});
};

Expand Down

0 comments on commit d961613

Please sign in to comment.