Opened 3 years ago

Last modified 14 months ago

#33113 assigned Cleanup/optimization

Add example to documentation of a DateInput with input_type='date'

Reported by: dennisvang Owned by: dennisvang
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by dennisvang)

Rationale

By default, the forms.widgets.DateInput widget renders as a simple text field.

However, a "date picker", like the one implemented in contrib.admin is often much more convenient.

Fortunately it is now possible to take advantage of the browser's built-in date picker, using the HTML <input type='date'> element.

The only problem is that, although the default DateInput can be easily modified to use the <input type='date'> element, this may not be so obvious to people unfamiliar with the inner workings of Django (e.g. forms.widgets.Input.input_type).

Moreover, some people may not even know the HTML type='date' exists, nor that browsers have built-in date pickers.

Request

I believe it would be very helpful if the documentation included an example, like these two provided by Tim Graham in ticket #33100:

class DateInput(forms.DateInput):
    input_type = 'date'

or

DateInput(attrs={'type': 'date'})

This has the additional advantage of documenting the use of the forms.widgets.Input.input_type attribute, which appears in the documentation but is not mentioned explicitly in the text, as far as I see.

If necessary, I would be willing to prepare a pull request for this.

Change History (10)

comment:1 by dennisvang, 3 years ago

Description: modified (diff)

comment:2 by Claude Paroz, 3 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

Yes, please. A note about why Django doesn't use this input type by default would be nice too.

comment:3 by dennisvang, 3 years ago

Owner: changed from nobody to dennisvang
Status: newassigned

in reply to:  2 comment:4 by dennisvang, 3 years ago

Replying to Claude Paroz:

Yes, please. A note about why Django doesn't use this input type by default would be nice too.

Would something like this do?

I'm not quite sure how to explain why input_type = 'date' is not the default.

Version 0, edited 3 years ago by dennisvang (next)

comment:5 by dennisvang, 3 years ago

Has patch: set

comment:6 by Carlton Gibson, 3 years ago

Patch needs improvement: set

Claude mention the discussion on #16630 on the PR which should touch on the why it's still a type=text by default.

Last edited 3 years ago by Carlton Gibson (previous) (diff)

comment:7 by Claude Paroz, 3 years ago

#33165 is a typical issue showing the difficulty of the date input. So the simple widget subclass with input_type = 'date' is NOT sufficient to make it work properly. The initial input value must also be converted to the YYYY-MM-DD format to comply with the specs.

comment:8 by Carlton Gibson, 3 years ago

There was a mailing list discussion raising some points, as well as those here and on the PR.

Capturing those succinctly is the remaining task here.

comment:9 by Natalia Bidart, 14 months ago

Pinged PR author to see if we can revive this effort (following recent ticket #34853).

comment:10 by Natalia Bidart, 14 months ago

Version: 3.2dev
Note: See TracTickets for help on using tickets.
Back to Top