Skip to content

Fixed "allowClear" when no "placeholder" is set (AssociationField)#3944

Merged
javiereguiluz merged 1 commit intoEasyCorp:masterfrom
liarco:master
Nov 18, 2020
Merged

Fixed "allowClear" when no "placeholder" is set (AssociationField)#3944
javiereguiluz merged 1 commit intoEasyCorp:masterfrom
liarco:master

Conversation

@liarco
Copy link
Copy Markdown
Contributor

@liarco liarco commented Nov 7, 2020

When trying to clear an AssociationField I get an error from Select2:
Schermata 2020-11-07 alle 14 45 12

This seems to be related to: https://stackoverflow.com/questions/49953467/cannot-read-property-id-of-undefined-select2
Select2 doc: https://select2.org/selections#clearable-selections

My solution: I simply check if allowClear is set (and true), then if placeholder is not set I set it to an empty value.

I tried to fix this in a simple way, but maybe you prefer a different solution, let me know.

Thank you for your time.

@liarco
Copy link
Copy Markdown
Contributor Author

liarco commented Nov 8, 2020

@javiereguiluz I'm afraid that #3925 introduced this regression. And now I think that my solution might not be enough since the bug also affects other Select2 inputs like the ChoiceField (does it use the same CrudAutocompleteType?).

If you have any preferred solution I can implement it and update this PR.

Thank you!

@javiereguiluz
Copy link
Copy Markdown
Collaborator

@liarco I saw this error a few days ago in one of my apps ... but now I cannot reproduce it anymore. Could you please update to the latest dev-master changes and see if the error is gone. I'm probably missing something, but let's double check. Thanks!

@liarco
Copy link
Copy Markdown
Contributor Author

liarco commented Nov 15, 2020

Hi @javiereguiluz, I tested using a1d8c1d and now association inputs with ->autocomplete() don't set data-allow-clear correctly.

I'm testing a brand new entity with a property which can be null, if I don't enable lazy-loading then the clear option works as intended (but I think it's because Select2 finds real options inside the <select> element), if I enable lazy-loading the x button disappears...

output2

Forcing the data-allow-clear setting the attr option fires the same error as before.

Please let me know if there's anything else I can do to help you troubleshooting.

@javiereguiluz javiereguiluz added this to the 3.x milestone Nov 18, 2020
@javiereguiluz
Copy link
Copy Markdown
Collaborator

Thanks for the new insights and the perfect GIF showing the problem. LEt's merge this! Thanks!

@javiereguiluz javiereguiluz merged commit 900df55 into EasyCorp:master Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants