Skip to content

Commit a43b6e6

Browse files
committed
Add a look sample via grouped_options_for_select
1 parent 7c9376e commit a43b6e6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

spec/example_app/app/dashboards/product_dashboard.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ class ProductDashboard < Administrate::BaseDashboard
2323
price: Field::Number.with_options(prefix: "$", decimals: 2),
2424
product_meta_tag: Field::HasOne.with_options(order: "meta_title"),
2525
release_year: Field::Select.with_options(
26-
collection: -> { (Time.current.year - 10)..Time.current.year }
26+
collection: -> {
27+
((Time.current.year - 10)..Time.current.year).to_a.reverse
28+
.group_by { |year| "'#{(year / 10) * 10}s" }
29+
},
30+
look: :group
2731
)
2832
}
2933

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<div class="field-unit__label">
2+
<%= f.label field.attribute %>
3+
</div>
4+
<div class="field-unit__field">
5+
<%=
6+
f.select(
7+
field.attribute,
8+
{include_blank: field.include_blank_option},
9+
data: {controller: field.html_controller}
10+
) do
11+
%>
12+
<%= grouped_options_for_select(
13+
field.selectable_options,
14+
field.data,
15+
prompt: true
16+
)
17+
%>
18+
<% end %>
19+
</div>

0 commit comments

Comments
 (0)