8000 Allow specifying custom input_html for DateRangeInput · activeadmin/activeadmin@a9006f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit a9006f9

Browse files
author
Michal Kováč
committed
Allow specifying custom input_html for DateRangeInput
closes #5864
1 parent f64464c commit a9006f9

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* Use filter label when condition has a predicate. [#5886] by [@ko-lem]
88
* Fix error when routing with array containing symbol. [#5870] by [@jwesorick]
9+
* Allow specifying custom input_html for DateRangeInput [#5864] by [@mirelon]
910

1011
### Removals
1112

@@ -524,10 +525,11 @@ Please check [0-6-stable] for previous changes.
524525
[#5548]: https://github.com/activeadmin/activeadmin/pull/5548
525526
[#5842]: https://github.com/activeadmin/activeadmin/pull/5842
526527
[#5854]: https://github.com/activeadmin/activeadmin/pull/5854
528+
[#5864]: https://github.com/activeadmin/activeadmin/pull/5864
527529
[#5874]: https://github.com/activeadmin/activeadmin/pull/5874
528530
[#5877]: https://github.com/activeadmin/activeadmin/pull/5877
529531
[#5886]: https://github.com/activeadmin/activeadmin/pull/5886
530-
[#5870]: https://github.com/activeadmin/activeadmin/pull/5870
532+
[#5867]: https://github.com/activeadmin/activeadmin/pull/5867
531533

532534
[@5t111111]: https://github.com/5t111111
533535
[@aarek]: https://github.com/aarek
@@ -578,6 +580,7 @@ Please check [0-6-stable] for previous changes.
578580
[@markstory]: https://github.com/markstory
579581
[@mauriciopasquier]: https://github.com/mauriciopasquier
580582
[@mconiglio]: https://github.com/mconiglio
583+
[@mirelon]: https://github.com/mirelon
581584
[@ndbroadbent]: https://github.com/ndbroadbent
582585
[@Nguyenanh]: https://github.com/Nguyenanh
583586
[@panasyuk]: https://github.com/panasyuk

lib/active_admin/inputs/filters/date_range_input.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def input_html_options(input_name = gt_input_name, placeholder = gt_input_placeh
3333
class: "datepicker",
3434
maxlength: 10,
3535
placeholder: placeholder,
36-
value: current_value ? current_value.strftime("%Y-%m-%d") : "" }
36+
value: current_value ? current_value.strftime("%Y-%m-%d") : "" }.merge(options[:input_html] || {})
3737
end
3838

3939
def gt_input_placeholder

spec/unit/filters/filter_form_builder_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,24 @@ def filter(name, options = {})
171171
it "should generate a date less than" do
172172
expect(body).to have_selector("input.datepicker[name='q[published_date_lteq]']")
173173
end
174+
175+
context "with input_html" do
176+
let(:body) { filter :published_date, input_html: { 'autocomplete': 'off' } }
177+
178+
it "should generate provided input html for both ends of date range" do
179+
expect(body).to have_selector("input.datepicker[name='q[published_date_gteq]'][autocomplete=off]")
180+
expect(body).to have_selector("input.datepicker[name='q[published_date_lteq]'][autocomplete=off]")
181+
end
182+
end
183+
184+
context "with input_html overriding the defaults" do
185+
let(:body) { filter :published_date, input_html: { 'class': 'custom_class' } }
186+
187+
it "should override the default attribute values for both ends of date range" do
188+
expect(body).to have_selector("input.custom_class[name='q[published_date_gteq]']")
189+
expect(body).to have_selector("input.custom_class[name='q[published_date_lteq]']")
190+
end
191+
end
174192
end
175193

176194
describe "datetime attribute" do
@@ -182,6 +200,24 @@ def filter(name, options = {})
182200
it "should generate a date less than" do
183201
expect(body).to have_selector("input.datepicker[name='q[created_at_lteq_datetime]']")
184202
end
203+
204+
context "with input_html" do
205+
let(:body) { filter :created_at, input_html: { 'autocomplete': 'off' } }
206+
207+
it "should generate provided input html for both ends of date range" do
208+
expect(body).to have_selector("input.datepicker[name='q[created_at_gteq_datetime]'][autocomplete=off]")
209+
expect(body).to have_selector("input.datepicker[name='q[created_at_lteq_datetime]'][autocomplete=off]")
210+
end
211+
end
212+
213+
context "with input_html overriding the defaults" do
214+
let(:body) { filter :created_at, input_html: { 'class': 'custom_class' } }
215+
216+
it "should override the default attribute values for both ends of date range" do
217+
expect(body).to have_selector("input.custom_class[name='q[created_at_gteq_datetime]']")
218+
expect(body).to have_selector("input.custom_class[name='q[created_at_lteq_datetime]']")
219+
end
220+
end
185221
end
186222

187223
describe "integer attribute" do

0 commit comments

Comments
 (0)
0