Sfoglia il codice sorgente

Fixed #35599 -- Added ColorInput widget.

arjunomray 8 mesi fa
parent
commit
946c3cf734

+ 1 - 0
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>

+ 1 - 0
django/forms/jinja2/django/forms/widgets/color.html

@@ -0,0 +1 @@
+{% include "django/forms/widgets/input.html" %}

+ 1 - 0
django/forms/templates/django/forms/widgets/color.html

@@ -0,0 +1 @@
+{% include "django/forms/widgets/input.html" %}

+ 6 - 0
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"

+ 11 - 0
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``
 ~~~~~~~~~~~~~~~
 

+ 4 - 0
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" ...>``.
 

+ 15 - 0
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'>",
+        )