Loading django/forms/fields.py +2 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ from django.core import validators from django.core.exceptions import ValidationError from django.forms.util import ErrorList, from_current_timezone, to_current_timezone from django.forms.widgets import ( TextInput, PasswordInput, EmailInput, HiddenInput, TextInput, PasswordInput, EmailInput, URLInput, HiddenInput, MultipleHiddenInput, ClearableFileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateInput, DateTimeInput, TimeInput, SplitDateTimeWidget, SplitHiddenDateTimeWidget, FILE_INPUT_CONTRADICTION Loading Loading @@ -612,6 +612,7 @@ class ImageField(FileField): return f class URLField(CharField): widget = URLInput default_error_messages = { 'invalid': _('Enter a valid URL.'), } Loading django/forms/widgets.py +6 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,8 @@ from django.utils.safestring import mark_safe from django.utils import datetime_safe, formats, six __all__ = ( 'Media', 'MediaDefiningClass', 'Widget', 'TextInput', 'EmailInput', 'PasswordInput', 'Media', 'MediaDefiningClass', 'Widget', 'TextInput', 'EmailInput', 'URLInput', 'PasswordInput', 'HiddenInput', 'MultipleHiddenInput', 'ClearableFileInput', 'FileInput', 'DateInput', 'DateTimeInput', 'TimeInput', 'Textarea', 'CheckboxInput', 'Select', 'NullBooleanSelect', 'SelectMultiple', 'RadioSelect', Loading Loading @@ -255,6 +256,10 @@ class EmailInput(TextInput): input_type = 'email' class URLInput(TextInput): input_type = 'url' class PasswordInput(TextInput): input_type = 'password' Loading docs/ref/forms/api.txt +1 −1 Original line number Diff line number Diff line Loading @@ -161,7 +161,7 @@ precedence:: >>> f = CommentForm(initial={'name': 'instance'}, auto_id=False) >>> print(f) <tr><th>Name:</th><td><input type="text" name="name" value="instance" /></td></tr> <tr><th>Url:</th><td><input type="text" name="url" /></td></tr> <tr><th>Url:</th><td><input type="url" name="url" /></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr> Accessing "clean" data Loading docs/ref/forms/fields.txt +4 −4 Original line number Diff line number Diff line Loading @@ -112,7 +112,7 @@ We've specified ``auto_id=False`` to simplify the output:: >>> f = CommentForm(auto_id=False) >>> print(f) <tr><th>Your name:</th><td><input type="text" name="name" /></td></tr> <tr><th>Your Web site:</th><td><input type="text" name="url" /></td></tr> <tr><th>Your Web site:</th><td><input type="url" name="url" /></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr> ``initial`` Loading @@ -135,7 +135,7 @@ field is initialized to a particular value. For example:: >>> f = CommentForm(auto_id=False) >>> print(f) <tr><th>Name:</th><td><input type="text" name="name" value="Your name" /></td></tr> <tr><th>Url:</th><td><input type="text" name="url" value="http://" /></td></tr> <tr><th>Url:</th><td><input type="url" name="url" value="http://" /></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr> You may be thinking, why not just pass a dictionary of the initial values as Loading @@ -150,7 +150,7 @@ and the HTML output will include any validation errors:: >>> f = CommentForm(default_data, auto_id=False) >>> print(f) <tr><th>Name:</th><td><input type="text" name="name" value="Your name" /></td></tr> <tr><th>Url:</th><td><ul class="errorlist"><li>Enter a valid URL.</li></ul><input type="text" name="url" value="http://" /></td></tr> <tr><th>Url:</th><td><ul class="errorlist"><li>Enter a valid URL.</li></ul><input type="url" name="url" value="http://" /></td></tr> <tr><th>Comment:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="comment" /></td></tr> This is why ``initial`` values are only displayed for unbound forms. For bound Loading Loading @@ -805,7 +805,7 @@ For each field, we describe the default widget used if you don't specify .. class:: URLField(**kwargs) * Default widget: :class:`TextInput` * Default widget: :class:`URLInput` * Empty value: ``''`` (an empty string) * Normalizes to: A Unicode object. * Validates that the given value is a valid URL. Loading docs/ref/forms/widgets.txt +11 −2 Original line number Diff line number Diff line Loading @@ -139,7 +139,7 @@ provided for each widget will be rendered exactly the same:: >>> f = CommentForm(auto_id=False) >>> f.as_table() <tr><th>Name:</th><td><input type="text" name="name" /></td></tr> <tr><th>Url:</th><td><input type="text" name="url"/></td></tr> <tr><th>Url:</th><td><input type="url" name="url"/></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr> On a real Web page, you probably don't want every widget to look the same. You Loading @@ -160,7 +160,7 @@ Django will then include the extra attributes in the rendered output: >>> f = CommentForm(auto_id=False) >>> f.as_table() <tr><th>Name:</th><td><input type="text" name="name" class="special"/></td></tr> <tr><th>Url:</th><td><input type="text" name="url"/></td></tr> <tr><th>Url:</th><td><input type="url" name="url"/></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" size="40"/></td></tr> .. _styling-widget-classes: Loading Loading @@ -403,6 +403,15 @@ These widgets make use of the HTML elements ``input`` and ``textarea``. Text input: ``<input type="email" ...>`` ``URLInput`` ~~~~~~~~~~~~ .. class:: URLInput .. versionadded:: 1.6 Text input: ``<input type="url" ...>`` ``PasswordInput`` ~~~~~~~~~~~~~~~~~ Loading Loading
django/forms/fields.py +2 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ from django.core import validators from django.core.exceptions import ValidationError from django.forms.util import ErrorList, from_current_timezone, to_current_timezone from django.forms.widgets import ( TextInput, PasswordInput, EmailInput, HiddenInput, TextInput, PasswordInput, EmailInput, URLInput, HiddenInput, MultipleHiddenInput, ClearableFileInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple, DateInput, DateTimeInput, TimeInput, SplitDateTimeWidget, SplitHiddenDateTimeWidget, FILE_INPUT_CONTRADICTION Loading Loading @@ -612,6 +612,7 @@ class ImageField(FileField): return f class URLField(CharField): widget = URLInput default_error_messages = { 'invalid': _('Enter a valid URL.'), } Loading
django/forms/widgets.py +6 −1 Original line number Diff line number Diff line Loading @@ -22,7 +22,8 @@ from django.utils.safestring import mark_safe from django.utils import datetime_safe, formats, six __all__ = ( 'Media', 'MediaDefiningClass', 'Widget', 'TextInput', 'EmailInput', 'PasswordInput', 'Media', 'MediaDefiningClass', 'Widget', 'TextInput', 'EmailInput', 'URLInput', 'PasswordInput', 'HiddenInput', 'MultipleHiddenInput', 'ClearableFileInput', 'FileInput', 'DateInput', 'DateTimeInput', 'TimeInput', 'Textarea', 'CheckboxInput', 'Select', 'NullBooleanSelect', 'SelectMultiple', 'RadioSelect', Loading Loading @@ -255,6 +256,10 @@ class EmailInput(TextInput): input_type = 'email' class URLInput(TextInput): input_type = 'url' class PasswordInput(TextInput): input_type = 'password' Loading
docs/ref/forms/api.txt +1 −1 Original line number Diff line number Diff line Loading @@ -161,7 +161,7 @@ precedence:: >>> f = CommentForm(initial={'name': 'instance'}, auto_id=False) >>> print(f) <tr><th>Name:</th><td><input type="text" name="name" value="instance" /></td></tr> <tr><th>Url:</th><td><input type="text" name="url" /></td></tr> <tr><th>Url:</th><td><input type="url" name="url" /></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr> Accessing "clean" data Loading
docs/ref/forms/fields.txt +4 −4 Original line number Diff line number Diff line Loading @@ -112,7 +112,7 @@ We've specified ``auto_id=False`` to simplify the output:: >>> f = CommentForm(auto_id=False) >>> print(f) <tr><th>Your name:</th><td><input type="text" name="name" /></td></tr> <tr><th>Your Web site:</th><td><input type="text" name="url" /></td></tr> <tr><th>Your Web site:</th><td><input type="url" name="url" /></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr> ``initial`` Loading @@ -135,7 +135,7 @@ field is initialized to a particular value. For example:: >>> f = CommentForm(auto_id=False) >>> print(f) <tr><th>Name:</th><td><input type="text" name="name" value="Your name" /></td></tr> <tr><th>Url:</th><td><input type="text" name="url" value="http://" /></td></tr> <tr><th>Url:</th><td><input type="url" name="url" value="http://" /></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr> You may be thinking, why not just pass a dictionary of the initial values as Loading @@ -150,7 +150,7 @@ and the HTML output will include any validation errors:: >>> f = CommentForm(default_data, auto_id=False) >>> print(f) <tr><th>Name:</th><td><input type="text" name="name" value="Your name" /></td></tr> <tr><th>Url:</th><td><ul class="errorlist"><li>Enter a valid URL.</li></ul><input type="text" name="url" value="http://" /></td></tr> <tr><th>Url:</th><td><ul class="errorlist"><li>Enter a valid URL.</li></ul><input type="url" name="url" value="http://" /></td></tr> <tr><th>Comment:</th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="comment" /></td></tr> This is why ``initial`` values are only displayed for unbound forms. For bound Loading Loading @@ -805,7 +805,7 @@ For each field, we describe the default widget used if you don't specify .. class:: URLField(**kwargs) * Default widget: :class:`TextInput` * Default widget: :class:`URLInput` * Empty value: ``''`` (an empty string) * Normalizes to: A Unicode object. * Validates that the given value is a valid URL. Loading
docs/ref/forms/widgets.txt +11 −2 Original line number Diff line number Diff line Loading @@ -139,7 +139,7 @@ provided for each widget will be rendered exactly the same:: >>> f = CommentForm(auto_id=False) >>> f.as_table() <tr><th>Name:</th><td><input type="text" name="name" /></td></tr> <tr><th>Url:</th><td><input type="text" name="url"/></td></tr> <tr><th>Url:</th><td><input type="url" name="url"/></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr> On a real Web page, you probably don't want every widget to look the same. You Loading @@ -160,7 +160,7 @@ Django will then include the extra attributes in the rendered output: >>> f = CommentForm(auto_id=False) >>> f.as_table() <tr><th>Name:</th><td><input type="text" name="name" class="special"/></td></tr> <tr><th>Url:</th><td><input type="text" name="url"/></td></tr> <tr><th>Url:</th><td><input type="url" name="url"/></td></tr> <tr><th>Comment:</th><td><input type="text" name="comment" size="40"/></td></tr> .. _styling-widget-classes: Loading Loading @@ -403,6 +403,15 @@ These widgets make use of the HTML elements ``input`` and ``textarea``. Text input: ``<input type="email" ...>`` ``URLInput`` ~~~~~~~~~~~~ .. class:: URLInput .. versionadded:: 1.6 Text input: ``<input type="url" ...>`` ``PasswordInput`` ~~~~~~~~~~~~~~~~~ Loading