simple_form
simple_form copied to clipboard
Generate HTML5 date/time inputs by default
It's a long time ago since HTML5 date/time support was included in simple_form https://github.com/heartcombo/simple_form/pull/935 and since then as the docs describe by default they are disabled https://github.com/heartcombo/simple_form/pull/1150 because at the time the browsers weren't ready for them, but I think now 8 years after, the browsers are ready as mdn browser compatibility suggests https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date#browser_compatibility, what do you think about simple_form turn on the generation of these html5 inputs by default?
This probably would be a breaking change and would require a major release, I suppose
This can be implemented without breaking change, but just add another config option which is false
by default:
# initializer
SimpleForm.setup do |config|
config.default_html5_date_time = false
end
# input helper (simple_form/inputs/date_time_input.rb#L34)
def use_html5_inputs?
input_options.fetch(:html5, SimpleForm.default_html5_date_time)
end
On a major release this can be switched to true
but not necessary
It looks like a bug to be honest. https://github.com/heartcombo/simple_form/blob/main/lib/simple_form/inputs/date_time_input.rb#L35 it doesn't use html5
config from the wrapper but uses html5
option from the input options. @carlosantoniodasilva do you thing we should make it work the same as e.g NumericInput works?
@nashby yes. I think we should match the behavior.
I just experienced this. For anyone reading, you have explicitly set html5: true, as: :date
on the field to have it render correctly.
I opened a PR for this. It's not a breaking change, but it's definitely a change to the default behavior since the generated default wrapper is using the html5
component.