Opened 5 years ago

Closed 6 months ago

Last modified 6 months ago

#33113 closed Cleanup/optimization (fixed)

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

Reported by: dennisvang Owned by: Samriddha Kumar Tripathi
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
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 (21)

comment:1 by dennisvang, 5 years ago

Description: modified (diff)

comment:2 by Claude Paroz, 5 years ago

Triage Stage: Unreviewed → Accepted
Type: Uncategorized → Cleanup/optimization

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

comment:3 by dennisvang, 5 years ago

Owner: changed from nobody to dennisvang
Status: new → assigned

in reply to:  2 comment:4 by dennisvang, 5 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.

Working on it here: ​https://github.com/dennisvang/django/tree/ticket_33113

Would something like ​this do?

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

Last edited 5 years ago by dennisvang (previous) (diff)

comment:5 by dennisvang, 5 years ago

Has patch: set

comment:6 by Carlton Gibson, 5 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 5 years ago by Carlton Gibson (previous) (diff)

comment:7 by Claude Paroz, 5 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, 5 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, 3 years ago

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

comment:10 by Natalia Bidart, 3 years ago

Version: 3.2 → dev

comment:11 by Samriddha Kumar Tripathi, 13 months ago

I Would like to work on this ticket

comment:12 by Samriddha Kumar Tripathi, 13 months ago

Owner: changed from dennisvang to Samriddha Kumar Tripathi

comment:14 by Samriddha Kumar Tripathi, 13 months ago

Patch needs improvement: unset

comment:15 by Samriddha Kumar Tripathi, 12 months ago

Patch needs improvement: set

comment:16 by Samriddha Kumar Tripathi, 12 months ago

Patch needs improvement: unset

comment:17 by Sarah Boyce, 6 months ago

Patch needs improvement: set

comment:18 by Samriddha Kumar Tripathi, 6 months ago

Patch needs improvement: unset

comment:19 by Sarah Boyce, 6 months ago

Triage Stage: Accepted → Ready for checkin

comment:20 by Sarah Boyce <42296566+sarahboyce@…>, 6 months ago

Resolution: → fixed
Status: assigned → closed

In 7dc826b9:

Fixed #33113 -- Documented usage and caveats of HTML5 date input in DateInput widget.

comment:21 by Sarah Boyce <42296566+sarahboyce@…>, 6 months ago

In 6f38a664:

[6.0.x] Fixed #33113 -- Documented usage and caveats of HTML5 date input in DateInput widget.

Backport of 7dc826b9758d634623a6f5ca05d0ca2048a0ce48 from main.

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