[Bug] select2_from_ajax defaults a selection on null column
See original GitHub issueBug report
What I did
I am using select2_from_ajax on a hasOneThrough relationship. Using the ‘include_all_form_fields’ => true feature I have my ajax call be dependent on the value of another field. That works fine. That is not the bug. The bug appears when I edit a record and the dependent select2_from_ajax is null in the table, but is populated with the first item in the database table.
What I expected to happen
The select2_from_ajax field should not have selected value on the edit screen when the column in the table is null.
What happened
The null column from the table had a selected value in the select2_from_ajax field. Note that the drop down is blank, but there is a “ghost” vale selected.
What I’ve already tried to fix it
I set the ajax function to return only an empty array and and an empty string, the issue was not resolved. I believe there must be a default action in the select2_from_ajax field that is getting data from the model when the edit screen loads and not from the ajax call. The ajax call is not made during the initial load of the edit screen, but when the drop down is clicked on.
Backpack, Laravel, PHP, DB version
When I run php artisan backpack:version
the output is:
PHP VERSION:
PHP 7.4.10 (cli) (built: Sep 9 2020 06:36:14) ( NTS ) Copyright © The PHP Group Zend Engine v3.4.0, Copyright © Zend Technologies with Zend OPcache v7.4.10, Copyright ©, by Zend Technologies
LARAVEL VERSION:
v7.28.3@b0942c391975972b1a54b2dc983e33a239f169a9
BACKPACK VERSION:
4.1.25@23fb1ed5153d5465d49d2fe1ca265a5985c78877
MySQL Version 8.0.17
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (6 by maintainers)
Top GitHub Comments
This is just a guess, but might be worth trying, could you setup your field name not with dots
.
but with dashes_
?Indeed it’s strange why it would happen in some entries but not in all. Maybe some cache stuff ? Try also:
php artisan cache:clear
Let me know the results, Pedro
Closing due inactivity.
Please re-open if the problem persists.