Skip to content

Commit 385c220

Browse files
authored
Adding missing boolean attributes arg for select input methods. Fixes #977 (#981)
1 parent 97a2cd9 commit 385c220

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

spec/lucky/ext/select_helpers_spec.cr

+20
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,24 @@ private class TestPage
1414
self
1515
end
1616

17+
def render_disabled_select(field)
18+
select_input field, attrs: [:disabled] do
19+
end
20+
self
21+
end
22+
1723
def render_multi_select(field)
1824
multi_select_input field do
1925
end
2026
self
2127
end
2228

29+
def render_disabled_multi_select(field)
30+
multi_select_input field, attrs: [:disabled] do
31+
end
32+
self
33+
end
34+
2335
def render_options(field, options)
2436
options_for_select(field, options)
2537
self
@@ -69,12 +81,20 @@ describe Lucky::SelectHelpers do
6981
view.render_select(form.company_id).html.to_s.should eq <<-HTML
7082
<select name="company:company_id"></select>
7183
HTML
84+
85+
view.render_disabled_select(form.company_id).html.to_s.should eq <<-HTML
86+
<select name="company:company_id" disabled></select>
87+
HTML
7288
end
7389

7490
it "renders multi-select" do
7591
view.render_multi_select(form.tags).html.to_s.should eq <<-HTML
7692
<select name="company:tags[]" multiple></select>
7793
HTML
94+
95+
view.render_disabled_multi_select(form.tags).html.to_s.should eq <<-HTML
96+
<select name="company:tags[]" multiple disabled></select>
97+
HTML
7898
end
7999

80100
it "renders options" do

src/lucky/ext/select_helpers.cr

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
module Lucky::SelectHelpers
2-
def select_input(field : Avram::PermittedAttribute, **html_options, &) : Nil
3-
select_tag merge_options(html_options, {"name" => input_name(field)}) do
2+
def select_input(field : Avram::PermittedAttribute, attrs : Array(Symbol) = [] of Symbol, **html_options, &) : Nil
3+
select_tag attrs, merge_options(html_options, {"name" => input_name(field)}) do
44
yield
55
end
66
end
77

8-
def multi_select_input(field : Avram::PermittedAttribute(Array), **html_options, &) : Nil
9-
select_tag [:multiple], merge_options(html_options, {"name" => input_name(field)}) do
8+
def multi_select_input(field : Avram::PermittedAttribute(Array), attrs : Array(Symbol) = [] of Symbol, **html_options, &) : Nil
9+
merged_attrs = [:multiple].concat(attrs)
10+
select_tag merged_attrs, merge_options(html_options, {"name" => input_name(field)}) do
1011
yield
1112
end
1213
end

0 commit comments

Comments
 (0)