diff --git a/spec/lucky/ext/select_helpers_spec.cr b/spec/lucky/ext/select_helpers_spec.cr index 16c1bd1df..e1c976bf1 100644 --- a/spec/lucky/ext/select_helpers_spec.cr +++ b/spec/lucky/ext/select_helpers_spec.cr @@ -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 @@ -69,12 +81,20 @@ describe Lucky::SelectHelpers do view.render_select(form.company_id).html.to_s.should eq <<-HTML HTML + + view.render_disabled_select(form.company_id).html.to_s.should eq <<-HTML + + HTML end it "renders multi-select" do view.render_multi_select(form.tags).html.to_s.should eq <<-HTML HTML + + view.render_disabled_multi_select(form.tags).html.to_s.should eq <<-HTML + + HTML end it "renders options" do diff --git a/src/lucky/ext/select_helpers.cr b/src/lucky/ext/select_helpers.cr index e70d40fa1..a8ed8c70c 100644 --- a/src/lucky/ext/select_helpers.cr +++ b/src/lucky/ext/select_helpers.cr @@ -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