platanus / activeadmin_addons

Extends ActiveAdmin to enable a set of great optional UX improving add-ons
MIT License
763 stars 288 forks source link

feat(tags-input): rework to return array #469

Closed difernandez closed 1 year ago

difernandez commented 1 year ago

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 set value and display_name, and having the addable 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:

https://github.com/platanus/activeadmin_addons/assets/12057523/76d36697-2deb-4fb3-bad3-793f62eab19a

Checklist

Before submitting the PR make sure the following are checked:

timothyrobb commented 1 year ago

Just leaving this here to confirm that this does indeed fix the issue we were experiencing with #421. Thank you for your work! Great job simplifying it in the process 💪 🎉

difernandez commented 1 year ago

Thanks for confirming, I'm glad it works!