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 )
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 , 3 years ago
Description: | modified (diff) |
---|
follow-up: 4 comment:2 by , 3 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Cleanup/optimization |
comment:3 by , 3 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 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.
comment:5 by , 3 years ago
Has patch: | set |
---|
Pull request: https://github.com/django/django/pull/14905
comment:6 by , 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.
comment:7 by , 3 years ago
comment:8 by , 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 , 14 months ago
Pinged PR author to see if we can revive this effort (following recent ticket #34853).
comment:10 by , 14 months ago
Version: | 3.2 → dev |
---|
Yes, please. A note about why Django doesn't use this input type by default would be nice too.