Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unselect events: cache lookup key fix #6179

Merged
merged 6 commits into from Oct 25, 2022
Merged

Unselect events: cache lookup key fix #6179

merged 6 commits into from Oct 25, 2022

Conversation

jayaddison
Copy link
Contributor

This pull request includes a

  • Bug fix
  • New feature
  • Translation

The following changes were made

  • During unselect events, retrieve the HTML option element related to the unselection and use that as a cache key to retrieve item data

If this is related to an existing ticket, include a link to it as well.

Resolves #6128.

@@ -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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this is somewhat intentionally not a complete-strict equality test (in other words: it is expected that this is == instead of ===)

This follows a similar equality pattern check in array.js here.

If both option-value and data-id are guaranteed to be of type string, then this could be upgraded to a strict equality test.

@kevin-brown kevin-brown reopened this Oct 25, 2022
@kevin-brown kevin-brown merged commit d961613 into select2:develop Oct 25, 2022
@jayaddison jayaddison deleted the issue-6128/selection-data-lookup branch October 25, 2022 08:56
@@ -114,7 +114,12 @@ define([
});

container.on('unselect', function (params) {
self.unselect(params.data);
container.$element.find('option').each(function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevin-brown I'm feeling a bit uncertain about whether this change is a good idea, after looking at it again.

This extra for loop feels like it could quite easily introduce performance regressions.

I'll find time to take another look at this soon, but if in any doubt, please feel free to revert this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(update: re-inspecting this changeset currently)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, a slightly stronger statement after re-reading the changeset and related issues: I think I'd prefer for this pull request to be reverted (and #6128 re-opened), if that's OK.

I didn't add any test coverage as part of the changes, which was unwise, because that makes it much harder to determine whether the modifications truly resolve the issue identified in the linked ticket.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(revert pull request opened as #6217)

kevin-brown pushed a commit that referenced this pull request Jan 29, 2023
jayaddison added a commit to openculinary/select2 that referenced this pull request Apr 3, 2023
jayaddison added a commit to openculinary/select2 that referenced this pull request Apr 3, 2023
arkonan pushed a commit to modolabs/select2 that referenced this pull request May 19, 2023
* 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
arkonan pushed a commit to modolabs/select2 that referenced this pull request May 19, 2023
p8 pushed a commit to p8/select2 that referenced this pull request Jan 11, 2024
* 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
p8 pushed a commit to p8/select2 that referenced this pull request Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot unselect by clicking selected when using dataAdapter
2 participants