simple_form icon indicating copy to clipboard operation
simple_form copied to clipboard

Generate HTML5 date/time inputs by default

Open marcelolx opened this issue 3 years ago • 5 comments

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

marcelolx avatar May 28 '21 17:05 marcelolx

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

attenzione avatar Dec 27 '21 16:12 attenzione

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 avatar Mar 08 '22 12:03 nashby

@nashby yes. I think we should match the behavior.

rafaelfranca avatar Apr 05 '22 22:04 rafaelfranca

I just experienced this. For anyone reading, you have explicitly set html5: true, as: :date on the field to have it render correctly.

jtarchie avatar Nov 20 '23 02:11 jtarchie

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.

jamezilla avatar Feb 14 '24 20:02 jamezilla