feat(tags-input): rework to return array#469
Merged
Merged
Conversation
Now it is based and behaves more like a Rails select with multiple: true. Blank value and new selected options are now handled under the hood because of it
ldlsegovia
approved these changes
Jun 8, 2023
ldlsegovia
left a comment
Contributor
There was a problem hiding this comment.
You simplified it a lot 👏🏻👏🏻👏🏻
|
Just leaving this here to confirm that this does indeed fix the issue we were experiencing with #421. |
Contributor
Author
|
Thanks for confirming, I'm glad it works! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation / Background
This Pull Request has been created because tags input has had some inconsistent behaviors in the past related to the string returned and the token that separated the tags in said string. Plus, it seemed a bit counter-intuitive that a tags/multiselect input returned a string instead of an array.
Closes #335
Closes #341
Closes #421
Detail
This Pull Request changes the tags input so it returns an array of strings instead of a token-separated string. It does so by relying on the default behavior of a regular rails select with
multiple: true. This allowed me to simplify the input a lot, as now a couple of things, such as hidden input with blank value and tracking of the array value, are done under the hood.The input now works almost identically as doing
f.input :foos, as: :select, multiple: true, with the added bonus of being able to setvalueanddisplay_name, and having theaddablefunction defined for non-AR relation uses.A disclaimer was added to inform of the return type and a gotcha present in multi selects that's important when using with Postgres' array column.
Additional information
With a
Purchasemodel that has:fooscolumn of Postgres array typeacts_as_taggable_on :aato_tags, from the library acts_as_taggable_onAnd an admin form with the following form:
It looks like this:
Screen.Recording.2023-06-07.at.11.07.27.mov
Checklist
Before submitting the PR make sure the following are checked: