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

Fix select2 search not auto focusing in jQuery 3.6.0 #187

Open
wants to merge 2 commits into
base: 4-4-stable
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/assets/javascripts/spree/backend/spree-select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ document.addEventListener("spree:load", function() {
placeholder: Spree.translations.select_an_option,
allowClear: true
})

if(jQuery().jquery === '3.6.0') {
Copy link
Member

Choose a reason for hiding this comment

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

Could you describe in more detail what changed in jquery 3.6 so that this if is required?
Also, if applying such a change it would be great to do a broader check e.g. if version is >= 3.6

Copy link
Author

Choose a reason for hiding this comment

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

Hi @rafalcymerys,

This pull request includes a fix for the search box not focusing immediately after the select is opened for clients using latest jquery v3.6.0. Please see the video below for the issue.

Spree-Administration-Products.webm

Note : I have changed the jQuery version check with broader check.

$(document).on('select2:open', () => {
document.querySelector('.select2-search__field').focus()
});
}
})

$.fn.addSelect2Options = function (data) {
Expand Down