0
0
mirror of https://github.com/django/django.git synced 2024-11-21 19:09:18 +01:00

Fixed #35599 -- Added ColorInput widget.

This commit is contained in:
arjunomray 2024-07-26 07:39:19 +02:00 committed by Sarah Boyce
parent 54e8b4e582
commit 946c3cf734
7 changed files with 39 additions and 0 deletions

View File

@ -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>

View File

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

View File

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

View File

@ -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"

View File

@ -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``
~~~~~~~~~~~~~~~

View File

@ -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" ...>``.

View File

@ -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'>",
)