-
Notifications
You must be signed in to change notification settings - Fork 25
Add multiple keyword/functionality to select
#64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
multiple and include_blank keywords to select
|
more details: Multiple select support# Multiple select with automatic [] appending and hidden input
field(:tag_ids).select(
[1, "Ruby"], [2, "Rails"], [3, "Phlex"],
multiple: true
)
# Renders: <input type="hidden" name="tag_ids[]" value="">
# <select name="tag_ids[]" multiple>...</select>Include blank option# Add blank option at the start
field(:country).select(
nil, [1, "USA"], [2, "Canada"], [3, "Mexico"]
)API harmonized with with radio component PR #65# Positional arguments
field(:role_id).select([1, 'Admin'], [2, 'Editor'], [3, 'Viewer'])
# ActiveRecord relations (wrapped in array)
field(:author_id).select(User.select(:id, :name))NotesMultiple select handling
Field naming logic# Single select
name="role_id"
# Multiple select
name="role_ids[]"
# Multiple select in collection
name="user[orders][0][tag_ids][]"
# Multiple select in Field collection (parent is Field)
name="users[][]" # No extra [] appendedForm integration testsIntegration tests to confirm Select works correctly in Rails forms: Single Select
Multiple Select
|
|
Feedback is similar to the radio buttons PR Eliminate the Eliminate the Similar to |
|
PR updated to reflect feedback. Question (also asked on #65, but relevant here) In Select currently, the # undocumented kwarg on main
field(:foo).select(collection: [[1, 'Admin'], [2, 'Editor']])
# positional
field(:foo).select([1, 'Admin'], [2, 'Editor'])Is this kwarg available just because of the way it's initialized? Or is this considered a feature undocumented in the README? Maybe nobody uses it, can add a deprecation notice if passed directly. |
multiple and include_blank keywords to selectmultiple keyword/functionality to select
An unexpected API gotcha i'm sure you're aware of:Superform This is a real gotcha for refactoring from ERB, it means devs have to manually flip all the arrays. It would be good to change this API. I can't imagine how to change it without breaking people's existing |
This is a reboot of PR #33. It intends to support the
multipleHTML spec for<select>elements.multiplekwarg to theselectmethod. Full backwards compatibility with the current API ofselect.select multiplefield correctly — i.e., using square brackets in a way that does not interfere with parent field notation. (It has to prevent double[]when multiple select is used inside collections.) See this conversation. Tests all permutations I could think of.multiple, to handle the way browsers handle blank selects (form value may not be submitted unless hidden field present)Selectcomponent param for the array of options fromcollectiontooptions(to avoid confusion with.collectionmethod, which creates FieldCollections). Backwards compatible, both keywords accepted.fieldvsField)Note, I realize you proposed a separate
multiple_selectcomponent method [in the discussion here] (#33 (comment)) and mentioned that also below, but I would suggest this is not really necessary or desirable, since the current PR maintains backwards compatibility with the current method signature. Keeping theselectlogic in one component seems to be the most intuitive and elegant way. In theselectHTML element spec,multipleis just an attribute, not a separate element.