question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] select2_from_ajax defaults a selection on null column

See original GitHub issue

Bug 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:closed
  • Created 3 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pxpmcommented, Oct 13, 2020

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

0reactions
pxpmcommented, Oct 27, 2020

Closing due inactivity.

Please re-open if the problem persists.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - select2 - how to allow a null value - Stack Overflow
To specify a null value you set the Select2 value to null and the placeholder will appear. $('select').select2({ placeholder: 'Your NULL ...
Read more >
Common problems - The jQuery replacement for select boxes
Select2 does not function properly when I use it inside a Bootstrap modal. This issue occurs because Bootstrap modals tend to steal focus...
Read more >
How to set selected value of jQuery Select2 - Edureka
I have a simple code of select2 that get data from AJAX. $("#programid").select2({ placeholder: "Select a Program", allowClear: true, ...
Read more >
Examples - Select2 - JeeSite
When using Select2 with remote data, the HTML required for the select is the same as any other Select2. If you need to...
Read more >
X-editable :: In-place editing with Twitter Bootstrap, jQuery UI ...
type - type of input (text, textarea, select, etc) ... List of values: http://api.jquery.com/jQuery.ajax ... If null , default input's display used.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found