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

Feature Request: Radio Buttons Across Rows #149

Open
temp1029 opened this issue Dec 27, 2019 · 4 comments
Open

Feature Request: Radio Buttons Across Rows #149

temp1029 opened this issue Dec 27, 2019 · 4 comments
Labels
request New feature or request

Comments

@temp1029
Copy link

I have a case where I only want one row to have a field selected at a time. This is entirely a front-end request, maybe just finding a way to link boolean fields together across rows with the same 'name' parameter.

@beliolfa beliolfa added the request New feature or request label Jan 31, 2020
@beliolfa
Copy link
Contributor

I think this is interesting. Can you develop a bit more that idea?

@temp1029
Copy link
Author

temp1029 commented Oct 16, 2020

Sure.

I currently use the Row field to allow users to populate a select on the public front-end, so it is defined like this:

Row::make('Specific Values', [
  R64Text::make('Value', 'value')->rules('required'),
  R64Text::make('Label', 'label'),
], 'allowed_values')`

Adding a third column like the below would allow the users to place a check on the value they want to be preselected on the front-end.

Row::make('Specific Values', [
  R64Text::make('Value', 'value')->rules('required'),
  R64Text::make('Label', 'label'),
  R64Boolean::make('Default?', 'default_value'),
], 'allowed_values')`

The issue is, when a boolean a checkbox is rendered they can select multiple "default" values where they should only be able to select one. Ideally we would be able to change the new line above to be something like this:

  R64Boolean::make('Default?', 'default_value')->onlySelectOne(),

For the nova admin panel I see two possible solutions to this:

  1. Render a radio button with the same name so the singular selection is handled by HTML.
  2. Still render the checkbox as a boolean but have Javascript which deselects all other checkboxes in that column.

Behind the scenes this would continue to be a boolean field. I think #2 would be easier (no need to create a custom field for rendering) and be more in-line with what users would expect to see. Also, given that you've already expanded the Nova core Boolean class you wouldn't need to create an entirely new form control.

@jwktje
Copy link

jwktje commented Sep 24, 2021

I would really like this too. I think the ->onlySelectOne() would be great

@temp1029
Copy link
Author

To further expand on my suggestion 2 above, I think you could hook into the 'toggle' method on the Boolean Form Field component. This could look at a meta value set from a method call in the Boolean class.

My knowledge of Vue isn't strong enough to know how to select other form components for the same type, but some usage of the custom event system in Vue would probably work. There might be a more "Nova" way to do it though.

I don't think you'd really even need to worry about only doing this when on a row, since outside of a row there would only be one instance of a field on a form anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants