From 6f38a664c543ddf5225c2ff279560d2e1881decb Mon Sep 17 00:00:00 2001 From: Samriddha9619 Date: Wed, 24 Sep 2025 23:32:06 +0530 Subject: [6.0.x] Fixed #33113 -- Documented usage and caveats of HTML5 date input in DateInput widget. Backport of 7dc826b9758d634623a6f5ca05d0ca2048a0ce48 from main. --- docs/ref/forms/widgets.txt | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/ref/forms/widgets.txt b/docs/ref/forms/widgets.txt index 8c19bf1206..70d5112293 100644 --- a/docs/ref/forms/widgets.txt +++ b/docs/ref/forms/widgets.txt @@ -652,6 +652,29 @@ These widgets make use of the HTML elements ``input`` and ``textarea``. :doc:`/topics/i18n/formatting`. ``%U``, ``%W``, and ``%j`` formats are not supported by this widget. + .. admonition:: Using the HTML5 "date" input type + + If you are targeting browsers that support the + `HTML5 "date" input type`_, you can override the ``input_type`` + attribute to enable the browser’s native date picker:: + + class MyDateInput(forms.DateInput): + input_type = "date" + format = "%Y-%m-%d" + + Alternatively:: + + DateInput(attrs={"type": "date"}, format="%Y-%m-%d") + + HTML5 date inputs expect values in the ISO format ``YYYY-MM-DD``. If a + different format is provided, the field may appear empty even when a + value exists. Setting the ``format`` attribute controls how Django + provides the value, but the browser controls how it is displayed. + Hence, the ``format`` attribute and the :setting:`DATE_INPUT_FORMATS` + setting will have no effect on the displayed value. + + .. _HTML5 "date" input type: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date + ``DateTimeInput`` ~~~~~~~~~~~~~~~~~ -- cgit v1.3