-
Notifications
You must be signed in to change notification settings - Fork 116
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
Date filter renders as text input #294
Comments
Hey, I didn't get what would expect it to render to. I see that both range and non-range version is rendered to |
Hey @bogdan, so for me, this renders as
However, this renders as an
I would have thought they should both render as |
I don't see how would
Maybe there is some magic on your end. However, I do admit there is need a feature to specify such input type on the application level. Let me think about it. |
Ah yes, maybe I did tweak that in the view! Well yes, I think it would be really handy to be able to render a For now I've worked around it with some jQuery:
Bit of a kludge but works fine! Thanks @bogdan 😄 |
I've consulted with some frontend developers, so they tell that there is no consensus that using So, here is my solution. We introduce a new option like class MyGrid
filter(:created_at, :date, html_options: {type: 'date'});
end Alternatively, if you want class BaseGrid
INPUT_TYPE_BY_FILTER_TYPE = {
date: :date,
}
def self.filter(name, type = :default, html_options: {}, **options, &block)
html_options[:type] ||= INPUT_TYPE_BY_FILTER_TYPE[type]
super(name, type, html_options: html_options, **options, &block)
end
end
class MyGrid < BaseGrid
filter(:created_at, :date)
end I want to confirm if it is working for you before implementing |
Thanks @bogdan this looks great! Only thing I'm thinking - might it make sense to call the parameter What do you think? |
Good idea, I would name it |
Agreed 👍 Brilliant thanks @bogdan! I look forward to this update. No rush of course 😄 |
Released version 1.6.2 |
E.g. the following:
filter(:year_end, :date)
Renders as:
<input class="year_end date_filter" type="text" name="clients_grid[year_end]" id="clients_grid_year_end">
Range works fine.
I think this function is culprit, specifically line 149 - calls
datagrid_default_filter
if no range specified:datagrid/lib/datagrid/form_builder.rb
Lines 138 to 151 in 1e01b18
And then
datagrid_default_filter
renders the filter as atext_field
:datagrid/lib/datagrid/form_builder.rb
Lines 43 to 46 in 1e01b18
Tempted to try and fix it but might be easier for you to! For now I'll probably just work around it with some good ol'jQuery ;)
Can I just say though this gem is brilliant. Really well designed and has everything I need. Awesome work @bogdan 👍
The text was updated successfully, but these errors were encountered: