By default, the `forms.widgets.DateInput` widget renders as a simple text
field.
However, a "date picker", like
[https://github.com/django/django/blob/stable/3.2.x/django/contrib/admin/widgets.py#L49
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 [https://developer.mozilla.org/en-
US/docs/Web/HTML/Element/input/date <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.
[https://github.com/django/django/blob/stable/3.2.x/django/forms/widgets.py#L288
forms.widgets.Input.input_type]).
Moreover, some people may not even know the HTML `type='date'` exists, nor
that [https://developer.mozilla.org/en-
US/docs/Web/HTML/Element/input/date#browser_compatibility browsers have
built-in date pickers].
== Request
I believe it would be very helpful if the documentation included an
example, like [https://code.djangoproject.com/ticket/33100#comment:6 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
[https://github.com/django/django/blob/stable/3.2.x/docs/ref/forms/widgets.txt#L507
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/33113>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> == Rationale
>
> By default, the `forms.widgets.DateInput` widget renders as a simple text
> field.
>
> However, a "date picker", like
> [https://github.com/django/django/blob/stable/3.2.x/django/contrib/admin/widgets.py#L49
> 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 [https://developer.mozilla.org/en-
> US/docs/Web/HTML/Element/input/date <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.
> [https://github.com/django/django/blob/stable/3.2.x/django/forms/widgets.py#L288
> forms.widgets.Input.input_type]).
>
> Moreover, some people may not even know the HTML `type='date'` exists,
> nor that [https://developer.mozilla.org/en-
> US/docs/Web/HTML/Element/input/date#browser_compatibility browsers have
> built-in date pickers].
>
> == Request
>
> I believe it would be very helpful if the documentation included an
> example, like [https://code.djangoproject.com/ticket/33100#comment:6
> 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
> [https://github.com/django/django/blob/stable/3.2.x/docs/ref/forms/widgets.txt#L507
> 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.
New description:
== Rationale
By default, the
[https://docs.djangoproject.com/en/3.2/ref/forms/widgets/#dateinput
== Request
or
{{{
DateInput(attrs={'type': 'date'})
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/33113#comment:1>
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
Comment:
Yes, please. A note about why Django doesn't use this input type by
default would be nice too.
--
Ticket URL: <https://code.djangoproject.com/ticket/33113#comment:2>
* owner: nobody => dvg
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/33113#comment:3>
Comment (by dvg):
Replying to [comment:2 Claude Paroz]:
> Yes, please. A note about why Django doesn't use this input type by
default would be nice too.
Would something like
[https://github.com/dennisvang/django/commit/b7a7cbb23bf2dbfbf128ea260de8208cd6f65e73
this] do?
I'm not quite sure how to explain why `input_type = 'date'` is not the
default.
--
Ticket URL: <https://code.djangoproject.com/ticket/33113#comment:4>
* has_patch: 0 => 1
Comment:
Pull request: https://github.com/django/django/pull/14905
--
Ticket URL: <https://code.djangoproject.com/ticket/33113#comment:5>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/33113#comment:6>
Comment (by Claude Paroz):
#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 [https://developer.mozilla.org
/en-US/docs/Web/HTML/Element/input/date specs].
--
Ticket URL: <https://code.djangoproject.com/ticket/33113#comment:7>
Comment (by Carlton Gibson):
There was a [https://groups.google.com/g/django-developers/c/wp-
pnzcB25o/m/D5gEOzPIAQAJ?utm_medium=email&utm_source=footer mailing list
discussion] raising some points, as well as those here and on the PR.
Capturing those succinctly is the remaining task here.
--
Ticket URL: <https://code.djangoproject.com/ticket/33113#comment:8>
Comment (by Natalia Bidart):
Pinged PR author to see if we can revive this effort (following recent
ticket #34853).
--
Ticket URL: <https://code.djangoproject.com/ticket/33113#comment:9>
* version: 3.2 => dev
--
Ticket URL: <https://code.djangoproject.com/ticket/33113#comment:10>