feat(tags-input): rework to return array #469
Merged
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 setvalue
anddisplay_name
, and having theaddable
function 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
Purchase
model that has:foos
column 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: