Proposal: Add opt-in `USE_HTML5_DATE_INPUT` setting for native browser date/time pickers

Hi!

Thanks for looking at this. For a few projects over the past 5 years, I’ve used native <input type=date> and friends, with custom widget subclasses. I think we’re ready to provide support in Django, but I’m not 100% sure on the plan to only provide a global setting that switches all forms over. Global switches are great for opting-in on new projects, but they’re not a useful tool for migrating existing codebases, where one often needs per-field control.

Additionally, BaseTemporalField (the base for DateField and friends), currently validates against locale-based formats, while <input type=date> and co. only send ISO8601 values. Your proposal has these keep working, but I think it would be best to avoid having unused parsing logic.

I think a gentler, more targeted plan would be better. The first release could do something like:

  1. Add NativeDateInput, NativeTimeInput, and NativeDateTimeInput widget classes (names to be bikeshedded).
  2. Add NativeDateField etc. that use these widgets by default.
  3. Move the admin to use them, rather than its custom widgets, with a per-ModelAdmin (?) option to switch back. (We can be more aggressive with the admin, as it’s a UI that we fully control.)
  4. Document how to use ModelFormOptions.formfield_callback to switch your forms to use the native fields.

We could also consider a global switch that changes the defaults for forms to native fields, but given there would be a snippet to copy for your base field class, that could wait for a later release, when any rough edges have been tested.

What do you think?

4 Likes