10000 Date Range fields broken after 2.5.0 release · Issue #5955 · activeadmin/activeadmin · GitHub
[go: up one dir, main page]

Skip to content

Date Range fields broken after 2.5.0 release #5955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kivanio opened this issue Dec 2, 2019 · 3 comments · Fixed by #5957
Closed

Date Range fields broken after 2.5.0 release #5955

kivanio opened this issue Dec 2, 2019 · 3 comments · Fixed by #5957

Comments

@kivanio
Copy link
Contributor
kivanio commented Dec 2, 2019

Expected behavior

Date Range fields broken after 2.5.0 release.
I believe that is related to #5867

If you configure:

filter :month, as: :date_range

Before 2.5.0 it creates the following html:
<div class="date_range input optional stringish filter_form_field filter_date_range" id="q_month_input"><label class="label">Mês</label> <input size="12" class="datepicker hasDatepicker" maxlength="10" placeholder="De" value="" type="text" name="q[month_gteq]" id="q_month_gteq"> <input size="12" class="datepicker hasDatepicker" maxlength="10" placeholder="Até" value="" type="text" name="q[month_lteq]" id="q_month_lteq"></div>

id="q_month_gteq"
id="q_month_lteq"

After 2.5.0:
<div class="date_range input optional stringish filter_form_field filter_date_range" id="q_month_input"><label for="q_month" class="label">Mês</label> <input class="datepicker hasDatepicker" value="" id="q_month" type="text" name="q[month_gteq]"> <input class="datepicker hasDatepicker" value="" id="q_month" type="text" name="q[month_lteq]"></div>

id="q_month"
id="q_month"

Actual behavior

The date picker does not work anymore because the IDs now are equal in both range fields.
And also it lost other html options like placeholder, maxlength.

All my date/datetime fields are broken like this example.

@deivid-rodriguez
Copy link
Member

Thanks for reporting this, I'll have a look at this ASAP.

@deivid-rodriguez
Copy link
Member

Pinging @mirelon just in case you have any ideas.

@mirelon
Copy link
Contributor
mirelon commented Dec 3, 2019

The problem is that #5867 calls input_html_options which uses Formtastic::Inputs::Base methods to generate option keys (id, placeholder, maxlength, size, required, autofocus, readonly).
The result is the duplication of id for both inputs (and other wrong options).
DateRangeInput is special, because for one input it generates two separate inputs (is there any other input, which consists of multiple sub-inputs?). It cannot use default Formtastic options and override DateRangeInput's default options and propagate them to all sub-inputs.
I suggest overriding default options not by calling Formtastic's input_html_options, but by calling (options[:input_html] || {}). In this way the programmer still can override options. The missing options are filled by ActionView in render method. E.g. the id is generated from method_name (gt_input_name and lt_input_name respectively) here: https://github.com/rails/rails/blob/master/actionview/lib/action_view/helpers/tags/base.rb#L119

mirelon pushed a commit to mirelon/activeadmin that referenced this issue Dec 3, 2019
mirelon pushed a commit to mirelon/activeadmin that referenced this issue Dec 3, 2019
mirelon pushed a commit to mirelon/activeadmin that referenced this issue Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
0