Skip to content
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

Allow extractElementAttributes to use a checkbox list #147

Closed
julianrubisch opened this issue Apr 13, 2020 · 2 comments · Fixed by #175
Closed

Allow extractElementAttributes to use a checkbox list #147

julianrubisch opened this issue Apr 13, 2020 · 2 comments · Fixed by #175
Labels
enhancement New feature or request
Milestone

Comments

@julianrubisch
Copy link
Contributor

Feature Request

extractElementAttributes for the moment returns multiple values for select tags with multiple: true:

https://github.com/hopsoft/stimulus_reflex/blob/480ee76dccf4ddc212602d1c3dee01216b6369ab/javascript/attributes.js#L37

A common scenario is to use a checkbox list for an association collection, as in collection_check_boxes:

https://devdocs.io/rails~6.0/actionview/helpers/formoptionshelper#method-i-collection_check_boxes

It would be nice if SR supported that out of the box.

Describe the solution you'd like

The hidden complexity lies in the fact that we'd have to consider multiple elements in extractElementAttributes, not just the one triggering the reflex. Still I think a library such as SR should take on that complexity instead of imposing it on the back end developer.

Specifically, I discovered this shortage when working on the permalink expo example and trying to employ a button group: https://github.com/hopsoft/stimulus_reflex_expo/pull/26/files#diff-23c58647594fccfb30d0b54554851d59R15

@hopsoft
Copy link
Contributor

hopsoft commented Apr 14, 2020

Are you thinking we should marshal attributes only for checked and selected options? Then store them under something like attrs.checkedOptions = [{...},{...},...] and attrs.selectedOptions = [{...},{...},...]?

@julianrubisch
Copy link
Contributor Author

Right. On the server side you’d get an array of checked options as in a multiple select

julianrubisch added a commit to julianrubisch/stimulus_reflex that referenced this issue Apr 26, 2020
julianrubisch added a commit to julianrubisch/stimulus_reflex that referenced this issue Apr 26, 2020
julianrubisch added a commit to julianrubisch/stimulus_reflex that referenced this issue Apr 26, 2020


- a predicate method to determine whether there are multiple options
present
- a generic collect method to get all checked values for either a
checkbox list or a multiple select
julianrubisch added a commit to julianrubisch/stimulus_reflex that referenced this issue Apr 26, 2020


- a predicate method to determine whether there are multiple options
present
- a generic collect method to get all checked values for either a
checkbox list or a multiple select
julianrubisch added a commit to julianrubisch/stimulus_reflex that referenced this issue Apr 27, 2020
julianrubisch added a commit to julianrubisch/stimulus_reflex that referenced this issue Apr 27, 2020
@hopsoft hopsoft added this to the 3.2.1 milestone May 9, 2020
@hopsoft hopsoft added the enhancement New feature or request label May 9, 2020
julianrubisch added a commit to julianrubisch/stimulus_reflex that referenced this issue May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants