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

Settings with data and ajax on a multiple select do not display selected items #89

Closed
Shoplifter opened this issue Dec 13, 2018 · 13 comments

Comments

@Shoplifter
Copy link

Hi @brianvoe
I try to use SlimSelect with following options:
image
This works without the data option, also without the ajax option, but both together wont.
Here are a few screenshots with what happens:
after loading the page:
image
opening the dropdown (you can see the disabled items that are actually selected)
image
After a click somewhere in the pulldown:
image
The selected items finally appear, but still not with the innerHTML form the data set.
When I scroll down, below the disabled options (only disabled, because already selected) the same options (functionally disabled, but visually enabled) show up a second time.
Searching and majax request work. If I add a new item, it is displayed correctly.
image

@brianvoe
Copy link
Owner

Thanks for submitting this. This is interesting. Let me do some tests to see if i can recreate this given you explanation of how your using it.

@Shoplifter
Copy link
Author

Shoplifter commented Jan 3, 2019

There's another issue, I ran into - may or may not be related to this(?)

Under certain conditions the preselected value is submitted twice. This is a big problem, because it causes some nasty exceptions when the value is tried to be saved to database with unique keys.
Maybe this would not occur if ajax response did not include already selected options. I dont know. Is there a way to pass these options to the ajax script (like the search parameter)?

I made up a simple reproducer for this issues. It uses PHP for ajax requests and for showing submitted values. Hope that helps

@Shoplifter Shoplifter reopened this Jan 4, 2019
@Shoplifter
Copy link
Author

Have you been able to reproduce these issues?

@brianvoe
Copy link
Owner

Im going to look into this tonight and see if i can replicate this.

@brianvoe
Copy link
Owner

So i was able to replicate this and I think im going to stick with(unless i get a really good reason not to) not auto selected options that have selected: true in it. I couldnt think of a reason why someone would need to auto select values upon doing an ajax request.

Change my mind.

@Shoplifter
Copy link
Author

@brianvoe
That seems to be a misunderstanding: The values shall and are NOT auto selected upon the ajax request, but on initialization with the data option. But if the in addition to that an ajax option is set too (used later in the process upon searching for further selectable options), then this does not work.
Having both options set, the ajax options seems to interfere with the data option.

Please reopen.

What about this other thing (double submit of preselected values)? Shall I open another separate issue for that?

@brianvoe
Copy link
Owner

brianvoe commented Feb 1, 2019

Ok the plot thickens on this. The tricky thing about the ajax functionality in general is maintaining selected data from data that doesnt exist in the actual dataset. It might be the case that i need to go back to the drawing board and rethink how this should work.

Im open to suggestions and ideas. Thanks.

@brianvoe brianvoe reopened this Feb 1, 2019
@stanolacko
Copy link

Very nice scenario for this is list of selected tags for article.

Is it any update for this issue?

@stanolacko
Copy link

Anyway, quick solution to show selected items in multiple with ajax is to add
this.slim.values(); into condition if (this.config.isAjax && selected) { in SlimSelect.prototype.setData = function (data) {
It's working but not tested with every scenarious

@yellow1912
Copy link

I'm not sure if I have the same error, but for me it seems like if you use ajax, then at the same time initializing the options with set causes issues.

@yellow1912
Copy link

I would like to re-visit this issue and explain it in much more details:

I'm using slimselect with vuejs, so I created a component for slim. Lets say that I have a form to edit a blog post, the blog post as a list of categories (multiple) that I use slimselect input.

  1. If the blog already has some selected categories
  2. When the vue component is initialized, I need to use setData to initialize the options
  3. If ajax is also enabled, then the selected options will not be shown

@CptChaos
Copy link

CptChaos commented Jun 17, 2020

I am having the same issue, for a situation much like the one given above. :)
I am building a custom CMS-like system where I want the editors to be able to edit relationships, like movies and TV shows. As there are a lot of them (for both), I use a multiple Slim Select with AJAX call to search for new items, but as it's the edit page, I also would like to load in the current related items prior adding items in with the AJAX call, which now don't show, even though I used the setData method.

@brianvoe
Copy link
Owner

New version of slim select has been released. If this is still an issue let me know and ill try to take care of it.

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

No branches or pull requests

5 participants