-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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 remote data : outdated text displayed on re-selection #5391
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Hi @mrp14 - I think that this is because That I encountered something very similar in openculinary/frontend#239 and was able to develop a small workaround - openculinary/frontend@53fa276 (the commit description is longer than the code change). I'm not sure what the expected behaviour should be here. AJAX datasources are probably a bit unusual; in many cases the list of |
Hello, IMHO the expected behavior should be that no remote data get cached at all by the component. AJAX datasources are not so unusual, especially in enterprise management applications. Personally, when I'm looking for an autocomplete/multiselect/dropdown/call it what you want component like select2, the ability to work with remote data is absolutely mandatory. I don't really work with jQuery anymore, but from what I remember I ended up using other alternatives, select2 feeling a bit clunky on several aspects. |
That seems reasonable @mrp14 - I've drafted a possible approach that would resolve this in #6282. It feels like there could be edge cases here though. For example: is it valid for a |
I don't think this is a problem to prevent developers from mixing both local and remote data. If anyone ever needs "hard-coded" values, they can include them in the response from their custom data source, integrating them with data from the database (or other sources). |
Ok. I think what you say is true, however I'd like to make sure we consider as many possible edge cases as we can. Another few that occur:
|
(I'm drafing a test HTML page to explore some of these possibilities at the moment. unit/integration test coverage is helpful, but sometimes it's helpful to use practical testing too) |
Tagging, pre- Also I've discovered a regression -- pressing the enter/return key in a multiselect seems to remove the last entry in a multiselect. I'm not sure yet whether that's a result of my changes or other commits since 4.0.13 - I'm tracking that down next. |
@kevin-brown I've found what I think is a regression in 181170f related to a |
@kevin-brown apologies: after attempting to write a minimal repro, I discovered that the problem is not in |
I was excited for a new hard to solve bug! But I'm glad to hear you were able to solve it outside of Select2 and that it wasn't actually a bug. |
You're right, "tagging" requires appropriate attention in this discussion. I don't think that deleting deselected custom options would pose a problem, as they are no longer relevant. However, perhaps you could introduce one or multiple configuration options to allow developers to handle these scenarios as they want to. By the way, two points of my own :
|
Mostly agreed. I think the naming of One nitpick though:
That seems like a feature request, so it's probably worth opening separately? |
That would totally be a feature request, I just felt it was missing when I was looking at the |
@mrp14 it's possible we should move this discussion to a separate issue thread, but: how would the suggested functionality differ from the existing callback parameter on |
One more edge case to consider: grouped data is valid for AJAX datasources. If we're removing empty |
The idea would be that the developer could provide to select2 the built tag object asynchronously, which would allow the developer to make an API call and create it server side for example. It would allow to compute the tag object and its metadata server side, while doing whatever needed at the same moment (i.e. persist the "tag" in database). An example code : $('select').select2({
createTag: function(params, success_callback) {
var term = $.trim(params.term);
if (term === '') {
success_callback(null);
return;
}
$.ajax({
type: 'post',
url: '/api/create-tag',
data: {
"tag-text": term
},
dataType: 'json',
success: function(response) {
//response is null or a valid select2 tag object with id, text and whatever needed metadata
success_callback(response);
},
error: function() {
success_callback(null);
}
});
}
}); |
Hello,
I have a select2 element with an ajax datasource. If a user selects a value, then deselects it and finally reselects it, while text has changed server-side for the same id, the old version of text is displayed instead of the new one.
I've been able to get around it by deleting options at selection, but of course this is not appropriate if select2 allows multiple selection (previous selected elements will be deleted too) :
Is there a way to disable or get around this caching behavior ? Or, at least, can I refresh by myself options after ajax response ?
Here is the classical select2 config :
The text was updated successfully, but these errors were encountered: