Add allow empty option for @selectize/selectize#2817
Add allow empty option for @selectize/selectize#2817nickcharlton merged 1 commit intothoughtbot:mainfrom
Conversation
f1f780a to
7682a2f
Compare
|
Hey! Thanks for the great work on Administrate so far! |
|
I’m thinking that, in the future, it might be nice to make this a plugin so users can choose whether they want to use Selectize or not—there are probably other good libraries out there too. But I don’t think we can go that far right now, so for the moment I think it’s best to just stay up to date with the latest Selectize. What do you think? @nickcharlton @pablobm |
|
I think we should try and get this in as soon as we can. @goosys, could you rebase and update the branch to resolve the conflicts?
Yeah, I've thought the same. I'd quite like to replace it with something that's primarily web components based. Even if we wrote our own for it. |
d061e8d to
4f9de88
Compare
|
Thanks! I can't access that link because it's invalid, but I'll spin up a review app and test it out. |
This does several things in one go, because they can't be done indepentantly: 1. Upgrades `@selectize/selectize` from v0.12 to v0.15, 2. Fixes thoughtbot#2545 (Selectize removes blank options from selects) 3. Closes thoughtbot#2790 (Add allow empty option) Updating Selectize improved the visibility of empty options without requiring custom CSS. However, due to compatibility issues between Selectize, Rails, and Stimulus/Turbo, this ended up being a larger change than expected. Right after upgrading to @selectize/selectize, forms started hanging. To address this, workaround is used. This issue is likely not limited to Selectize. It seems that every time we use a JS library, we’ll need to implement a teardown() function to avoid similar problems. Switching from disconnect() to teardown() also prevents a regression of thoughtbot#2811. To prevent unintended removal when using `include_blank: false`, we also introduce a workaround to prevent unintended deletions. Finally, when updating a form with include_blank and navigating back via Turbo, the placeholder would display only its first character. A full page reload would render it correctly. To workaround this problem, we use a placeholder of `---` instead of a meaningful string so that it doesn't look wrong. thoughtbot#2545 thoughtbot#2790 hotwired/stimulus#104 (comment) thoughtbot#2811 selectize/selectize.js#1498 Updated selectize from 0.12 to @selectize/selectize 0.15 Used teardown instead of disconnect to address reinitialization issues Refactor select for @selectize/selectize
4f9de88 to
4411f61
Compare
|
Thanks! |
This change brake the ability to type and filter the select list when |
|
@radwo, if that's a new problem since this, can you open a new issue and mention this one? |
Updating @selectize/selectize (v0.12 -> 0.15) and revisiting #2790
Updating Selectize improved the visibility of empty options without requiring custom CSS. However, due to compatibility issues between Selectize, Rails, and Stimulus/Turbo, this ended up being a larger change than expected.
Preventing form hangs after updating Selectize
Right after upgrading to @selectize/selectize, forms started hanging. To address this, I applied a workaround in the second commit:
hotwired/stimulus#104 (comment)
This issue is likely not limited to Selectize. It seems that every time we use a JS library, we’ll need to implement a
teardown()function to avoid similar problems.Switching from
disconnect()toteardown()also prevents a regression of #2811.Reintroducing
allowEmptyOptionAdding
allowEmptyOptionagain worked perfectly as expected.I also tested the new
showEmptyOptionInDropdownoption, but it didn’t quite fit our use case, so I decided not to use it.Preventing unintended removal when
include_blank: falseI encountered an issue where pressing Backspace would remove the selection, even when
include_blank: falsewas set.Since Selectize doesn’t provide a built-in option for this, I added a (somewhat quirky) workaround in
select_controllerto prevent unintended deletions.Additionally, since Selectize doesn’t properly recognize the
requiredattribute onselect_tag, I had to manually add the constraint viadataattributes.Workaround for placeholder rendering issue
After resolving most of the issues, I ran into one last problem:
When updating a form with
include_blankand navigating back via Turbo, the placeholder would display only its first character. A full page reload would render it correctly.selectize/selectize.js#1498
I couldn't find a proper fix for this, so we’ll have to wait for an update from Selectize.
As a workaround, I set the placeholder to
---instead of a meaningful string. This way, even if only one character is displayed, it won’t look out of place. 😄