diff options
| author | Jeremy Thompson <jeremythompson.918@gmail.com> | 2024-07-17 16:50:01 +0100 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-07-31 13:11:45 +0200 |
| commit | 30a60e84923c18f3b2c725f7a31e521a833b8057 (patch) | |
| tree | 80224aef71d105ed92a6517ce82da70939cdf59e | |
| parent | 3f880890699d4412cf23b59dba425111f62afb3a (diff) | |
Fixed #35598 -- Added SearchInput widget.
| -rw-r--r-- | AUTHORS | 1 | ||||
| -rw-r--r-- | django/forms/jinja2/django/forms/widgets/search.html | 1 | ||||
| -rw-r--r-- | django/forms/templates/django/forms/widgets/search.html | 1 | ||||
| -rw-r--r-- | django/forms/widgets.py | 6 | ||||
| -rw-r--r-- | docs/ref/forms/widgets.txt | 11 | ||||
| -rw-r--r-- | docs/releases/5.2.txt | 3 | ||||
| -rw-r--r-- | tests/forms_tests/widget_tests/test_searchinput.py | 12 |
7 files changed, 34 insertions, 1 deletions
@@ -495,6 +495,7 @@ answer newbie questions, and generally made Django that much better: Jeremy Carbaugh <jcarbaugh@gmail.com> Jeremy Dunck <jdunck@gmail.com> Jeremy Lainé <jeremy.laine@m4x.org> + Jeremy Thompson <https://jhthompson.ca> Jerin Peter George <jerinpetergeorge@gmail.com> Jesse Young <adunar@gmail.com> Jezeniel Zapanta <jezeniel.zapanta@gmail.com> diff --git a/django/forms/jinja2/django/forms/widgets/search.html b/django/forms/jinja2/django/forms/widgets/search.html new file mode 100644 index 0000000000..08b1e61c0b --- /dev/null +++ b/django/forms/jinja2/django/forms/widgets/search.html @@ -0,0 +1 @@ +{% include "django/forms/widgets/input.html" %} diff --git a/django/forms/templates/django/forms/widgets/search.html b/django/forms/templates/django/forms/widgets/search.html new file mode 100644 index 0000000000..08b1e61c0b --- /dev/null +++ b/django/forms/templates/django/forms/widgets/search.html @@ -0,0 +1 @@ +{% include "django/forms/widgets/input.html" %} diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 4fae110d5e..e7717c2ff6 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -30,6 +30,7 @@ __all__ = ( "NumberInput", "EmailInput", "URLInput", + "SearchInput", "PasswordInput", "HiddenInput", "MultipleHiddenInput", @@ -353,6 +354,11 @@ class URLInput(Input): template_name = "django/forms/widgets/url.html" +class SearchInput(Input): + input_type = "search" + template_name = "django/forms/widgets/search.html" + + class PasswordInput(Input): input_type = "password" template_name = "django/forms/widgets/password.html" diff --git a/docs/ref/forms/widgets.txt b/docs/ref/forms/widgets.txt index f76759b254..1a868c32fa 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" ...>`` +``SearchInput`` +~~~~~~~~~~~~~~~ + +.. versionadded:: 5.2 + +.. class:: SearchInput + + * ``input_type``: ``'search'`` + * ``template_name``: ``'django/forms/widgets/search.html'`` + * Renders as: ``<input type="search" ...>`` + ``PasswordInput`` ~~~~~~~~~~~~~~~~~ diff --git a/docs/releases/5.2.txt b/docs/releases/5.2.txt index 5d5887fe34..ba9a3dfd4c 100644 --- a/docs/releases/5.2.txt +++ b/docs/releases/5.2.txt @@ -165,7 +165,8 @@ File Uploads Forms ~~~~~ -* ... +* The new :class:`~django.forms.SearchInput` form widget is for entering search + queries and renders as ``<input type="search" ...>``. Generic Views ~~~~~~~~~~~~~ diff --git a/tests/forms_tests/widget_tests/test_searchinput.py b/tests/forms_tests/widget_tests/test_searchinput.py new file mode 100644 index 0000000000..b11ffaaa82 --- /dev/null +++ b/tests/forms_tests/widget_tests/test_searchinput.py @@ -0,0 +1,12 @@ +from django.forms import SearchInput + +from .base import WidgetTest + + +class SearchInputTest(WidgetTest): + widget = SearchInput() + + def test_render(self): + self.check_html( + self.widget, "search", "", html='<input type="search" name="search">' + ) |
