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

ajax datasources: remove locally-cached 'option' HTML element during item unselection #6282

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

jayaddison
Copy link
Contributor

This pull request includes a

  • Bug fix
  • New feature
  • Translation

The following changes were made

  • Remove locally-cached HTML <option> elements from the DOM when an AJAX-sourced item is unselected.
  • This should allow the data received from AJAX-based (re)selections to be refreshed.

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

May resolve #5391.
Based upon / may be combined with #6241.

…tem that the updated text from the remote datasource is applied to the <option> element
'No items should be selected'
);

var queryTerms = ['firstQuery', 'secondQuery', 'thirdQuery', 'fourthQuery'];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems like a really smelly way to achieve multiple visits and actions on the select2 control. My JavaScript-fu isn't great, so there's almost certainly a better way to do this.

@jayaddison jayaddison marked this pull request as ready for review October 18, 2023 19:37
@jayaddison
Copy link
Contributor Author

Moving this pull request into a 'draft' status; option groups (nested results) need to be handled too.

@jayaddison jayaddison marked this pull request as draft October 21, 2023 13:32
@jayaddison
Copy link
Contributor Author

Moving this pull request into a 'draft' status; option groups (nested results) need to be handled too.

From testing locally: option groups do not result in the creation of nested HTML elements in the DOM-cached data; a flattened set of <option> elements are stored, the same as for flat datasources.

As a result: I don't think that any special-case handling is required for option groups, and I'll put this pull request back into a 'ready for review' state.

The testing methodology I used was to create a small Python script to generate dummy nested JSON data in the select2 data format and to run that every few seconds by using watch -n 2 python write_data.py to (re)write JSON data to file.

In combination with a basic test HTML page (loading JQuery and Select2 JS and CSS files) with a <select multiple> and some select2({ajax: ...}) configuration, and python -m http.server -b 127.0.0.1 to serve the data and HTML statically, that was enough to test some dynamic grouped result querying, selection, and unselection.

@jayaddison jayaddison marked this pull request as ready for review October 22, 2023 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ajax remote data : outdated text displayed on re-selection
1 participant