Opened 3 years ago

Last modified 15 months ago

#33113 assigned Cleanup/optimization

Add example to documentation of a DateInput with input_type='date' — at Version 1

Reported by: dennisvang Owned by: nobody
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 (1)

comment:1 by dennisvang, 3 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top