Closed schwern closed 4 years ago
In addition, DateRangeInput#input_html_options_for
was merging with input_html_options
backwards. If input_html_options
had a value or placeholder (even if nil), the merge would wipe out the the placeholder and value from input_html_options_for
.
So it's input_html_options.merge(new_options)
not new_options.merge(input_html_options)
to ensure the new placeholder and value are set.
And finally, it has to be converted to a format which includes the time. current_value&.strftime("%Y-%m-%d %H:%M")
vs current_value.strftime("%Y-%m-%d")
.
Hello @schwern
Thanks 🙏 for detailed 🔬 explanation of an issue.
Also your config/initializers/init_datetimepicker.rb
might be useful.
I'll take a look at this issue this/next weak.
PS: Since you use DateTime, I would like to mention about timezone. The plugin does not know about difference of user(Web) and database time-zones. So you might check(logs/development.log) if the SQL query is what you actually expect.
We encountered a problem where the date time range filter would show up with both fields having the placeholder "From". After submission the the lteq field would be set to the gteq field.
Here's the filter.
start
is adatetime
column.Showing the From/From.
Different values filled in.
After submission, To is set to From, but the original inputs were understood.
Upon investigation we noticed the IDs are
q_field_gteq
andq_field_lteq
for a Date rather thanq_field_gteq_datetimepicker
andq_field_lteq_datetimepicker
for a DateTime.I believe this is because ActiveAdmin::Inputs::Filters::DateTimeRangeInput inherits ActiveAdmin::Inputs::Filters::DateRangeInput#input_html_options which casts the value to a Date. This was added a few years ago.
This results in
DateTimeRangeInput#gt_input_name
andDateTimeRangeInput#lt_input_name
both using the name from their superclass DateRangeInput.The following monkey patch fixes the issue for us.
Here's our relevant Gemfile.lock.