summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--django/forms/jinja2/django/forms/widgets/color.html1
-rw-r--r--django/forms/templates/django/forms/widgets/color.html1
-rw-r--r--django/forms/widgets.py6
-rw-r--r--docs/ref/forms/widgets.txt11
-rw-r--r--docs/releases/5.2.txt4
-rw-r--r--tests/forms_tests/widget_tests/test_colorinput.py15
7 files changed, 39 insertions, 0 deletions
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 <anze@pecar.me>
Aram Dulyan
arien <regexbot@gmail.com>
+ Arjun Omray <arjunomray@gmail.com>
Armin Ronacher
Aron Podrigal <aronp@guaranteedplus.com>
Arsalan Ghassemi <arsalan.ghassemi@gmail.com>
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: ``<input type="url" ...>``
+``ColorInput``
+~~~~~~~~~~~~~~
+
+.. versionadded:: 5.2
+
+.. class:: ColorInput
+
+ * ``input_type``: ``'color'``
+ * ``template_name``:``'django/forms/widgets/color.html'``
+ * Renders as: ``<input type='color' ...>``
+
``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 ``<input type='color' ...>``.
+ 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 ``<input type="search" ...>``.
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="<input type='color' name='color'>",
+ )