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
Laravel / PHP - Items being deleted after selecting another #5037
Comments
Could we please see your client-side (Javascript) code? FYI, if you're going to be offering a list of 2000+ items, I'd strongly recommend that you consider using AJAX and pagination rather than rendering all of the items in the initial page load. |
Thanks for the feedback @alexweissman.
I will consider doing in ajax, how would that pagination you cited? does it automatically or do I need some code? If you can give me an example, I'm grateful. |
Pagination isn't fully documented yet, but in the meantime there is an example here: https://select2.org/data-sources/ajax#additional-examples Of course, you need to make sure that your remote data source can perform filtering and pagination on the server side. If you're using Laravel 5.5, they have a new feature that makes it easier to set up JSON APIs: https://laravel.com/docs/5.5/eloquent-resources |
Pagination is now documented: https://select2.org/data-sources/ajax#pagination |
I have not found yet, if I find I'll come back with an answer. Thanks |
Prerequisites
master
branch of Select2Steps to reproduce the issue
{!! Form::select('id_cargo[]', $cargos, (isset($usuarioCargos))? $usuarioCargos : null, ['id' => 'id_cargo', 'class' => 'form-control select2', 'multiple' => 'multiple']) !!}
PS.: I'm not using ajax requests. I tried to use loop, and put the id's manually, the problem persists. Other functions of select2 work normally, but I have this problem in changing already populated data coming from the database. Here's the demo below.
Demo with data coming from the database, the first item is deleted, then the second is also removed. After that, I test with the data contained in the front end, add two items, I delete the first and the second remains, this would be the ideal behavior to be used also with the data coming from the database.
Note: My list has more than 2,000 items, but I believe this should not interfere.
Expected behavior and actual behavior
I would like to keep the data after selecting another, or after deleting a single item. This works if the data isn't populated from the database, only on the front-end.
Environment
Browsers
Operating System
Libraries
Isolating the problem
The text was updated successfully, but these errors were encountered: