Skip to content

Commit

Permalink
Adding missing boolean attributes arg for select input methods. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoertink authored Nov 1, 2023
1 parent 97a2cd9 commit 385c220
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
20 changes: 20 additions & 0 deletions spec/lucky/ext/select_helpers_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,24 @@ private class TestPage
self
end

def render_disabled_select(field)
select_input field, attrs: [:disabled] do
end
self
end

def render_multi_select(field)
multi_select_input field do
end
self
end

def render_disabled_multi_select(field)
multi_select_input field, attrs: [:disabled] do
end
self
end

def render_options(field, options)
options_for_select(field, options)
self
Expand Down Expand Up @@ -69,12 +81,20 @@ describe Lucky::SelectHelpers do
view.render_select(form.company_id).html.to_s.should eq <<-HTML
<select name="company:company_id"></select>
HTML

view.render_disabled_select(form.company_id).html.to_s.should eq <<-HTML
<select name="company:company_id" disabled></select>
HTML
end

it "renders multi-select" do
view.render_multi_select(form.tags).html.to_s.should eq <<-HTML
<select name="company:tags[]" multiple></select>
HTML

view.render_disabled_multi_select(form.tags).html.to_s.should eq <<-HTML
<select name="company:tags[]" multiple disabled></select>
HTML
end

it "renders options" do
Expand Down
9 changes: 5 additions & 4 deletions src/lucky/ext/select_helpers.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module Lucky::SelectHelpers
def select_input(field : Avram::PermittedAttribute, **html_options, &) : Nil
select_tag merge_options(html_options, {"name" => input_name(field)}) do
def select_input(field : Avram::PermittedAttribute, attrs : Array(Symbol) = [] of Symbol, **html_options, &) : Nil
select_tag attrs, merge_options(html_options, {"name" => input_name(field)}) do
yield
end
end

def multi_select_input(field : Avram::PermittedAttribute(Array), **html_options, &) : Nil
select_tag [:multiple], merge_options(html_options, {"name" => input_name(field)}) do
def multi_select_input(field : Avram::PermittedAttribute(Array), attrs : Array(Symbol) = [] of Symbol, **html_options, &) : Nil
merged_attrs = [:multiple].concat(attrs)
select_tag merged_attrs, merge_options(html_options, {"name" => input_name(field)}) do
yield
end
end
Expand Down

0 comments on commit 385c220

Please sign in to comment.