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 search not works #2671

Closed
adaniello opened this issue Oct 18, 2021 · 3 comments
Closed

Ajax search not works #2671

adaniello opened this issue Oct 18, 2021 · 3 comments

Comments

@adaniello
Copy link

Ajax/JSON support, "the highlight" of 1.14.0-beta release (https://github.com/snapappointments/bootstrap-select/releases/tag/v1.14.0-beta), seems not works.

My code is very simple (see at https://codepen.io/adaniello/pen/xxLVrKE) and returns some issues:

  1. ajax search, in some conditions, renders a list with some items duplicated;
  2. ajax search with two results post an high number of ajax calls due a logical error (as reported in Ajax search get multiple calls #2659);
  3. "defocus", eg. by typing arrows, not works;
  4. selection not works.

Is there someone who managed to make it work?

I already fixed 1 and 2 points (a pull-request will be available when all point fixed), but i'ld like to get some feedback on this issues.

Thanks

@adaniello adaniello added the bug label Oct 18, 2021
@adaniello adaniello changed the title Ajax support not works Ajax search not works Oct 18, 2021
@adaniello
Copy link
Author

After debug, i fixed 1, 2 and 3 (other tests required). About 4th point, i noticed that the value of selected option, after search, is set correctly but placeholder "Nothing selected" isn't updated (works only if items loaded by "source.data").

Thanks

@NicolasCARPi
Copy link
Collaborator

Hello @adaniello, could you make different PR for your fixes please?

Make sure to base on the dev branch and target that branch for the PR!

@timkerkrade
Copy link

Hi @adaniello, it seems to me the problem with 4. is the following.
In a 'non-ajax-search' scenario the selectpicker keeps track of two arrays:

selectpicker.main
selectpicker.current

main has all entries, current only the entries which match with the search-string. But, both lists point to the same objects. So if an item in the 'current' list gets selected, it is selected in the 'main' list also.

When using ajax-search, it looks like the 'main' list gets populated with items from 'load', and 'current' with items from 'search'. In the rendering process the control takes the 'main' list to determine which one should be selected. So a selection after a 'search' doesn't have any effect in this scenario.

I'm not a 100% sure this issue causes all the troubles; but I think when adding items to 'current', the key of this items should be looked up first in 'main'. New items could be added to 'main' also, existing items should use the same object in 'current' and 'main'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants