-
-
Notifications
You must be signed in to change notification settings - Fork 292
enhancement: grouped options for select #3885
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
Conversation
Code Climate has analyzed commit 99c14a3 and detected 2 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
Thanks @adrianthedev for drafting this — this would be a great addition to the Select field! If I understand the proposed API correctly, it requires explicitly specifying grouped_options instead of the current options. That definitely makes the API very clear and explicit. That said, I was wondering if it might be more idiomatic to continue using the existing options parameter and add a bit of logic under the hood to automatically detect whether the provided options are grouped. IMHO this would make the API simpler and possibly more intuitive. What do you think? |
Hi @adrienpoly
Could you please share two examples of how you expect to provide options, and how you would expect Avo to group them? |
From the grouped_options_for_select api page These are 2 valid structure for grouped_options: Array syntax options = [
['North America',
[['United States','US'],'Canada']],
['Europe',
['Denmark','Germany','France']]
] or Hash syntax options = {
'North America' => [['United States','US'], 'Canada'],
'Europe' => ['Denmark','Germany','France']
} From the options_for_select api page
In AVOField is always defined like that field :country, as: select, options: options and inside the component we have a Then in the current PR implementation we would have something like def options
if grouped_options?(@field.options_for_select)
grouped_options_for_select(@field.options_for_select, selected: @field.value)
else
options_for_select(@field.options_for_select, selected: @field.value)
end
end
def grouped_options?(options)
....
end |
Got it, thanks for the detailed explanation. I think we could build an algorithm to detect that. I'm not sure we can guarantee 100% accuracy across all use cases, but it seems feasible. Now I wonder, why didn't Rails already do this? Why do they have both They probably could have offered just I get your point, but I see only one advantage here, and I'm not sure we can truly call it an advantage. Instead of writing What's the real benefit of that? I'm not sure what Adrian's stance is, but my position is to keep things super simple. I'd prefer to build an interface in Avo that delegates directly to Rails, Let me know if I'm missing a strong case where this abstraction would be genuinely beneficial. |
I agree with your points and it is a good call to point that Rails is keeping this as separate methods
The only thing I can think of is that is was the first thing I tried (pass a nested hash to options) without looking into the documentation (RTFM 😄 ). |
This PR has been marked as stale because there was no activity for the past 15 days. |
This PR has been merged into Please check the release guide for more information. |
Description
Add
grouped_options
for select, check docs for more info.Checklist: