#33113: Add example to documentation of a DateInput with input_type='date'
-------------------------------+--------------------------------------
     Reporter:  dvg            |                    Owner:  nobody
         Type:  Uncategorized  |                   Status:  new
    Component:  Documentation  |                  Version:  3.2
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------
Description changed by dvg:

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
 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#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.a49db40917bc2ec3e22a5ce0fb3b0623%40djangoproject.com.

Reply via email to