Skip to content

Commit c3c5394

Browse files
committed
Prioritize input_options over default ones. bogdan#319
1 parent 40eff47 commit c3c5394

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

lib/datagrid/form_builder.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ module FormBuilder
1010
# * <tt>text_field</tt> for other filter types
1111
def datagrid_filter(filter_or_attribute, partials: nil, **options, &block)
1212
filter = datagrid_get_filter(filter_or_attribute)
13-
self.send(
14-
filter.form_builder_helper_name, filter,
15-
**filter.input_options,
16-
**add_html_classes(options, filter.name, datagrid_filter_html_class(filter)),
17-
&block
18-
)
13+
options = add_html_classes({**filter.input_options, **options}, filter.name, datagrid_filter_html_class(filter))
14+
self.send( filter.form_builder_helper_name, filter, **options, &block)
1915
end
2016

2117
# @param filter_or_attribute [Datagrid::Filters::BaseFilter, String, Symbol] filter object or filter name

spec/datagrid/form_builder_spec.rb

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,12 @@ class MyTemplate
260260
end
261261
context "with enum filter type" do
262262
let(:_filter) { :category }
263+
let(:_category_filter_options) { {} }
263264
let(:_grid) {
265+
filter_options = _category_filter_options
264266
test_report do
265267
scope {Entry}
266-
filter(:category, :enum, :select => ["first", "second"])
267-
filter(:category_without_include_blank, :enum, :select => ["first", "second"], :include_blank => false)
268-
filter(:category_with_prompt, :enum, :select => ["first", "second"], :prompt => "My Prompt")
268+
filter(:category, :enum, select: ["first", "second"], **filter_options)
269269
end
270270
}
271271
it { should equal_to_dom(
@@ -299,21 +299,15 @@ class MyTemplate
299299
)}
300300
end
301301
context "with include_blank option set to false" do
302-
let(:_filter) { :category_without_include_blank }
302+
let(:_category_filter_options) { { include_blank: false } }
303303
it { should equal_to_dom(
304-
'<select class="category_without_include_blank enum_filter" name="report[category_without_include_blank]" id="report_category_without_include_blank">
304+
'<select class="category enum_filter" name="report[category]" id="report_category">
305305
<option value="first">first</option>
306306
<option value="second">second</option></select>'
307307
)}
308308
end
309309
context "with dynamic include_blank option" do
310-
let(:_grid) do
311-
test_report do
312-
scope {Entry}
313-
filter(:category, :enum, :select => ["first", "second"], :include_blank => proc { "Choose plz" })
314-
end
315-
end
316-
let(:_filter) { :category }
310+
let(:_category_filter_options) { {include_blank: proc { "Choose plz" }} }
317311
it { should equal_to_dom(
318312
'<select class="category enum_filter" name="report[category]" id="report_category">
319313
<option value="">Choose plz</option>
@@ -323,21 +317,24 @@ class MyTemplate
323317
end
324318

325319
context "with prompt option" do
326-
let(:_filter) { :category_with_prompt }
320+
let(:_category_filter_options) { {prompt: 'My Prompt'} }
327321
it { should equal_to_dom(
328-
'<select class="category_with_prompt enum_filter" name="report[category_with_prompt]" id="report_category_with_prompt"><option value="">My Prompt</option>
322+
'<select class="category enum_filter" name="report[category]" id="report_category"><option value="">My Prompt</option>
323+
<option value="first">first</option>
324+
<option value="second">second</option></select>'
325+
)}
326+
end
327+
328+
context "with input_options class" do
329+
let(:_category_filter_options) { {input_options: {class: 'custom-class'}} }
330+
it { should equal_to_dom(
331+
'<select class="custom-class category enum_filter" name="report[category]" id="report_category"><option value="" label=" "></option>
329332
<option value="first">first</option>
330333
<option value="second">second</option></select>'
331334
)}
332335
end
333336
context "with checkboxes option" do
334-
let(:_grid) do
335-
test_report do
336-
scope {Entry}
337-
filter(:category, :enum, :select => ["first", "second"], :checkboxes => true)
338-
end
339-
end
340-
let(:_filter) { :category }
337+
let(:_category_filter_options) { {checkboxes: true} }
341338
it { should equal_to_dom(
342339
'
343340
<label class="category enum_filter checkboxes" for="report_category_first"><input id="report_category_first" type="checkbox" value="first" name="report[category][]" />first</label>

0 commit comments

Comments
 (0)