Skip to content

Commit 7dc826b

Browse files
Samriddha9619sarahboyce
authored andcommitted
Fixed #33113 -- Documented usage and caveats of HTML5 date input in DateInput widget.
1 parent d61f33f commit 7dc826b

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

docs/ref/forms/widgets.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,29 @@ These widgets make use of the HTML elements ``input`` and ``textarea``.
646646
:doc:`/topics/i18n/formatting`. ``%U``, ``%W``, and ``%j`` formats are not
647647
supported by this widget.
648648

649+
.. admonition:: Using the HTML5 "date" input type
650+
651+
If you are targeting browsers that support the
652+
`HTML5 "date" input type`_, you can override the ``input_type``
653+
attribute to enable the browser’s native date picker::
654+
655+
class MyDateInput(forms.DateInput):
656+
input_type = "date"
657+
format = "%Y-%m-%d"
658+
659+
Alternatively::
660+
661+
DateInput(attrs={"type": "date"}, format="%Y-%m-%d")
662+
663+
HTML5 date inputs expect values in the ISO format ``YYYY-MM-DD``. If a
664+
different format is provided, the field may appear empty even when a
665+
value exists. Setting the ``format`` attribute controls how Django
666+
provides the value, but the browser controls how it is displayed.
667+
Hence, the ``format`` attribute and the :setting:`DATE_INPUT_FORMATS`
668+
setting will have no effect on the displayed value.
669+
670+
.. _HTML5 "date" input type: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
671+
649672
``DateTimeInput``
650673
~~~~~~~~~~~~~~~~~
651674

0 commit comments

Comments
 (0)