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

Skip to content

Commit 6e4c6a3

Browse files
author
Michal Kováč
committed
Allow specifying custom input_html for DateRangeInput
closes activeadmin#5864
1 parent dcff714 commit 6e4c6a3

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/active_admin/inputs/filters/date_range_input.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ def input_html_options(input_name = gt_input_name, placeholder = gt_input_placeh
2929
rescue
3030
nil
3131
end
32-
{ size: 12,
33-
class: "datepicker",
34-
maxlength: 10,
35-
placeholder: placeholder,
36-
value: current_value ? current_value.strftime("%Y-%m-%d") : "" }
32+
(options[:input_html] || {}).merge size: 12,
33+
class: "datepicker",
34+
maxlength: 10,
35+
placeholder: placeholder,
36+
value: current_value ? current_value.strftime("%Y-%m-%d") : ""
3737
end
3838

3939
def gt_input_placeholder

spec/unit/filters/filter_form_builder_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ 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
174183
end
175184

176185
describe "datetime attribute" do
@@ -182,6 +191,15 @@ def filter(name, options = {})
182191
it "should generate a date less than" do
183192
expect(body).to have_selector("input.datepicker[name='q[created_at_lteq_datetime]']")
184193
end
194+
195+
context "with input_html" do
196+
let(:body) { filter :created_at, input_html: { 'autocomplete': 'off' } }
197+
198+
it "should generate provided input html for both ends of date range" do
199+
expect(body).to have_selector("input.datepicker[name='q[created_at_gteq_datetime]'][autocomplete=off]")
200+
expect(body).to have_selector("input.datepicker[name='q[created_at_lteq_datetime]'][autocomplete=off]")
201+
end
202+
end
185203
end
186204

187205
describe "integer attribute" do

0 commit comments

Comments
 (0)
0