From 946c3cf7342cc40c2d8e3d865c96a4ec990f76f4 Mon Sep 17 00:00:00 2001 From: arjunomray Date: Fri, 26 Jul 2024 07:39:19 +0200 Subject: [PATCH] Fixed #35599 -- Added ColorInput widget. --- AUTHORS | 1 + .../forms/jinja2/django/forms/widgets/color.html | 1 + .../templates/django/forms/widgets/color.html | 1 + django/forms/widgets.py | 6 ++++++ docs/ref/forms/widgets.txt | 11 +++++++++++ docs/releases/5.2.txt | 4 ++++ tests/forms_tests/widget_tests/test_colorinput.py | 15 +++++++++++++++ 7 files changed, 39 insertions(+) create mode 100644 django/forms/jinja2/django/forms/widgets/color.html create mode 100644 django/forms/templates/django/forms/widgets/color.html create mode 100644 tests/forms_tests/widget_tests/test_colorinput.py diff --git a/AUTHORS b/AUTHORS index faf6420618..11ba2c89a4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -112,6 +112,7 @@ answer newbie questions, and generally made Django that much better: Anže Pečar Aram Dulyan arien + Arjun Omray Armin Ronacher Aron Podrigal Arsalan Ghassemi diff --git a/django/forms/jinja2/django/forms/widgets/color.html b/django/forms/jinja2/django/forms/widgets/color.html new file mode 100644 index 0000000000..08b1e61c0b --- /dev/null +++ b/django/forms/jinja2/django/forms/widgets/color.html @@ -0,0 +1 @@ +{% include "django/forms/widgets/input.html" %} diff --git a/django/forms/templates/django/forms/widgets/color.html b/django/forms/templates/django/forms/widgets/color.html new file mode 100644 index 0000000000..08b1e61c0b --- /dev/null +++ b/django/forms/templates/django/forms/widgets/color.html @@ -0,0 +1 @@ +{% include "django/forms/widgets/input.html" %} diff --git a/django/forms/widgets.py b/django/forms/widgets.py index e7717c2ff6..f1e233865c 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -30,6 +30,7 @@ __all__ = ( "NumberInput", "EmailInput", "URLInput", + "ColorInput", "SearchInput", "PasswordInput", "HiddenInput", @@ -354,6 +355,11 @@ class URLInput(Input): template_name = "django/forms/widgets/url.html" +class ColorInput(Input): + input_type = "color" + template_name = "django/forms/widgets/color.html" + + class SearchInput(Input): input_type = "search" template_name = "django/forms/widgets/search.html" diff --git a/docs/ref/forms/widgets.txt b/docs/ref/forms/widgets.txt index 1a868c32fa..bd970f1517 100644 --- a/docs/ref/forms/widgets.txt +++ b/docs/ref/forms/widgets.txt @@ -558,6 +558,17 @@ These widgets make use of the HTML elements ``input`` and ``textarea``. * ``template_name``: ``'django/forms/widgets/url.html'`` * Renders as: ```` +``ColorInput`` +~~~~~~~~~~~~~~ + +.. versionadded:: 5.2 + +.. class:: ColorInput + + * ``input_type``: ``'color'`` + * ``template_name``:``'django/forms/widgets/color.html'`` + * Renders as: ```` + ``SearchInput`` ~~~~~~~~~~~~~~~ diff --git a/docs/releases/5.2.txt b/docs/releases/5.2.txt index b732e98c9f..cb57b9255c 100644 --- a/docs/releases/5.2.txt +++ b/docs/releases/5.2.txt @@ -166,6 +166,10 @@ File Uploads Forms ~~~~~ +* The new :class:`~django.forms.ColorInput` form widget is for entering a color + in ``rrggbb`` hexadecimal format and renders as ````. + Some browsers support a visual color picker interface for this input type. + * The new :class:`~django.forms.SearchInput` form widget is for entering search queries and renders as ````. diff --git a/tests/forms_tests/widget_tests/test_colorinput.py b/tests/forms_tests/widget_tests/test_colorinput.py new file mode 100644 index 0000000000..f316534bfa --- /dev/null +++ b/tests/forms_tests/widget_tests/test_colorinput.py @@ -0,0 +1,15 @@ +from django.forms import ColorInput + +from .base import WidgetTest + + +class ColorInputTest(WidgetTest): + widget = ColorInput() + + def test_render(self): + self.check_html( + self.widget, + "color", + "", + html="", + )