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

[4.1][Bug] Relationship with InlineCreate allows_null not working due to missing empty option placeholder #2760

Closed
warton opened this issue May 4, 2020 · 5 comments
Assignees
Labels

Comments

@warton
Copy link

warton commented May 4, 2020

Bug report

What I did

I set my relationship field to allow inline_create and 'allows_null' => true

What I expected to happen

When my relationship field is set, I cannot unset it as the underlying select is missing empty option as required https://select2.org/placeholders:

For single selects only, in order for the placeholder value to appear, you must have a blank <option> as the first option in your <select> control. This is because the browser tries to select the first option by default. If your first option were non-empty, the browser would display this instead of the placeholder

What happened

My set value remained populated and didn't unset.

What I've already tried to fix it

The fix is easy for me. I've added to blade: crud/fields/relationship/fetch_or_create.blade.php:115

{{-- allow clear --}}
    @if ($field['allows_null'])
        <option value="" selected>
            {{ $field['placeholder'] }}
        </option>
    @endif

I didn't try fetch.blade.php, but I suppose it's the same issue there.

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

PHP VERSION:

PHP 7.4.4 (cli) (built: Mar 17 2020 13:49:19) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Xdebug v2.8.1, Copyright (c) 2002-2019, by Derick Rethans

LARAVEL VERSION:

v7.9.2@757b155658ae6da429065ba8f22242fe599824f7

BACKPACK VERSION:

4.1.x-dev@71cff08a82f925f014e815d2daa9190b6f2e5f5f

@welcome
Copy link

welcome bot commented May 4, 2020

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

  • Bug Reports, Feature Requests - Github Issues (here);
  • Quick help (How do I do X) - Gitter Chatroom;
  • Long questions (I have done X and Y and it won't do Z wtf) - Stackoverflow, using the backpack-for-laravel tag;
  • Showing off something you've made, asking for opinion on Backpack/Laravel matters - Reddit;

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

--
Justin Case
The Backpack Robot

@warton warton changed the title [4.1][Bug] InlineCreate allows_null not working due to missing empty option placeholder [4.1][Bug] Relationship with InlineCreate allows_null not working due to missing empty option placeholder May 4, 2020
@pxpm pxpm self-assigned this May 4, 2020
@pxpm
Copy link
Contributor

pxpm commented May 4, 2020

@warton Thank you very much for spotting and providing a solution.

I'v just submited PR: #2765

As soon as it gets merged a composer update should provide you with the fix.

Also note that multiple selects does not need the empty placeholder. From select2 docs:

For single selects only, in order for the placeholder value to appear, you must have a blank

and fetch_and_create and fetch handle both multiple and non-multiple, so I updated your fix with that information in mind.

Going to close this, any further addressing should be done in the PR thread.

Thanks again @warton

@pxpm pxpm closed this as completed May 4, 2020
@warton
Copy link
Author

warton commented May 5, 2020

cool, thx :)

@tabacitu
Copy link
Member

tabacitu commented May 5, 2020

Merged! A composer update backpack/crud should do it for you @warton

@warton
Copy link
Author

warton commented May 5, 2020

Yes, it works as expected. Thank you guys, you're the best! :)

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

No branches or pull requests

3 participants