diff options
| author | Samriddha9619 <sumitkumartripathi0@gmail.com> | 2025-09-24 23:32:06 +0530 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2026-04-13 09:06:08 +0200 |
| commit | 6f38a664c543ddf5225c2ff279560d2e1881decb (patch) | |
| tree | 66422a590eefbf2746e6a169331a8222e43cd2b9 /docs | |
| parent | 339b72f3c4a10037a345d88763622bb9e78c2a6b (diff) | |
[6.0.x] Fixed #33113 -- Documented usage and caveats of HTML5 date input in DateInput widget.
Backport of 7dc826b9758d634623a6f5ca05d0ca2048a0ce48 from main.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/forms/widgets.txt | 23 |
1 files changed, 23 insertions, 0 deletions
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`` ~~~~~~~~~~~~~~~~~ |
