mirror of https://github.com/django/django.git
Fixed #35601 -- Added TelInput widget.
This commit is contained in:
parent
946c3cf734
commit
b478cae006
1
AUTHORS
1
AUTHORS
|
@ -624,6 +624,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
Lowe Thiderman <lowe.thiderman@gmail.com>
|
Lowe Thiderman <lowe.thiderman@gmail.com>
|
||||||
Luan Pablo <luanpab@gmail.com>
|
Luan Pablo <luanpab@gmail.com>
|
||||||
Lucas Connors <https://www.revolutiontech.ca/>
|
Lucas Connors <https://www.revolutiontech.ca/>
|
||||||
|
Lucas Esposito <espositolucas95@gmail.com>
|
||||||
Luciano Ramalho
|
Luciano Ramalho
|
||||||
Lucidiot <lucidiot@brainshit.fr>
|
Lucidiot <lucidiot@brainshit.fr>
|
||||||
Ludvig Ericson <ludvig.ericson@gmail.com>
|
Ludvig Ericson <ludvig.ericson@gmail.com>
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{% include "django/forms/widgets/input.html" %}
|
|
@ -0,0 +1 @@
|
||||||
|
{% include "django/forms/widgets/input.html" %}
|
|
@ -32,6 +32,7 @@ __all__ = (
|
||||||
"URLInput",
|
"URLInput",
|
||||||
"ColorInput",
|
"ColorInput",
|
||||||
"SearchInput",
|
"SearchInput",
|
||||||
|
"TelInput",
|
||||||
"PasswordInput",
|
"PasswordInput",
|
||||||
"HiddenInput",
|
"HiddenInput",
|
||||||
"MultipleHiddenInput",
|
"MultipleHiddenInput",
|
||||||
|
@ -365,6 +366,11 @@ class SearchInput(Input):
|
||||||
template_name = "django/forms/widgets/search.html"
|
template_name = "django/forms/widgets/search.html"
|
||||||
|
|
||||||
|
|
||||||
|
class TelInput(Input):
|
||||||
|
input_type = "tel"
|
||||||
|
template_name = "django/forms/widgets/tel.html"
|
||||||
|
|
||||||
|
|
||||||
class PasswordInput(Input):
|
class PasswordInput(Input):
|
||||||
input_type = "password"
|
input_type = "password"
|
||||||
template_name = "django/forms/widgets/password.html"
|
template_name = "django/forms/widgets/password.html"
|
||||||
|
|
|
@ -580,6 +580,28 @@ These widgets make use of the HTML elements ``input`` and ``textarea``.
|
||||||
* ``template_name``: ``'django/forms/widgets/search.html'``
|
* ``template_name``: ``'django/forms/widgets/search.html'``
|
||||||
* Renders as: ``<input type="search" ...>``
|
* Renders as: ``<input type="search" ...>``
|
||||||
|
|
||||||
|
``TelInput``
|
||||||
|
~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
.. versionadded:: 5.2
|
||||||
|
|
||||||
|
.. class:: TelInput
|
||||||
|
|
||||||
|
* ``input_type``: ``'tel'``
|
||||||
|
* ``template_name``: ``'django/forms/widgets/tel.html'``
|
||||||
|
* Renders as: ``<input type="tel" ...>``
|
||||||
|
|
||||||
|
Browsers perform no client-side validation by default because telephone
|
||||||
|
number formats vary so much around the world. You can add some by setting
|
||||||
|
``pattern``, ``minlength``, or ``maxlength`` in the :attr:`Widget.attrs`
|
||||||
|
argument.
|
||||||
|
|
||||||
|
Additionally, you can add server-side validation to your form field with a
|
||||||
|
validator like :class:`~django.core.validators.RegexValidator` or via
|
||||||
|
third-party packages, such as `django-phonenumber-field`_.
|
||||||
|
|
||||||
|
.. _django-phonenumber-field: https://django-phonenumber-field.readthedocs.io/en/latest/index.html
|
||||||
|
|
||||||
``PasswordInput``
|
``PasswordInput``
|
||||||
~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -173,6 +173,9 @@ Forms
|
||||||
* The new :class:`~django.forms.SearchInput` form widget is for entering search
|
* The new :class:`~django.forms.SearchInput` form widget is for entering search
|
||||||
queries and renders as ``<input type="search" ...>``.
|
queries and renders as ``<input type="search" ...>``.
|
||||||
|
|
||||||
|
* The new :class:`~django.forms.TelInput` form widget is for entering telephone
|
||||||
|
numbers and renders as ``<input type="tel" ...>``.
|
||||||
|
|
||||||
Generic Views
|
Generic Views
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
from django.forms import TelInput
|
||||||
|
|
||||||
|
from .base import WidgetTest
|
||||||
|
|
||||||
|
|
||||||
|
class TelInputTest(WidgetTest):
|
||||||
|
widget = TelInput()
|
||||||
|
|
||||||
|
def test_render(self):
|
||||||
|
self.check_html(
|
||||||
|
self.widget, "telephone", "", html='<input type="tel" name="telephone">'
|
||||||
|
)
|
Loading…
Reference in New Issue