diff options
| author | Claude Paroz <claude@2xlibre.net> | 2012-09-10 19:21:29 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2012-09-10 19:31:11 +0200 |
| commit | f1bdfbd24bcc76d21c4bf7442959bdf630ac4dec (patch) | |
| tree | 5ca2a6f040a5106253d1ffdb3ad179d544b83211 /django | |
| parent | 611a2b266b2f57f42e4a3f0ac04d560e805c08cf (diff) | |
Document and test 'type' usage in Widget attrs
Refs #16630.
Diffstat (limited to 'django')
| -rw-r--r-- | django/forms/fields.py | 2 | ||||
| -rw-r--r-- | django/forms/widgets.py | 18 |
2 files changed, 12 insertions, 8 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py index 7f0d26d1aa..124e4f669a 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -199,7 +199,7 @@ class CharField(Field): def widget_attrs(self, widget): attrs = super(CharField, self).widget_attrs(widget) - if self.max_length is not None and isinstance(widget, (TextInput, PasswordInput)): + if self.max_length is not None and isinstance(widget, TextInput): # The HTML attribute is maxlength, not max_length. attrs.update({'maxlength': str(self.max_length)}) return attrs diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 7651efccd0..763da0cff2 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -260,10 +260,17 @@ class Input(Widget): final_attrs['value'] = force_text(self._format_value(value)) return format_html('<input{0} />', flatatt(final_attrs)) + class TextInput(Input): input_type = 'text' -class PasswordInput(Input): + def __init__(self, attrs=None): + if attrs is not None: + self.input_type = attrs.pop('type', self.input_type) + super(TextInput, self).__init__(attrs) + + +class PasswordInput(TextInput): input_type = 'password' def __init__(self, attrs=None, render_value=False): @@ -400,9 +407,8 @@ class Textarea(Widget): flatatt(final_attrs), force_text(value)) -class DateInput(Input): - input_type = 'text' +class DateInput(TextInput): def __init__(self, attrs=None, format=None): super(DateInput, self).__init__(attrs) if format: @@ -431,9 +437,8 @@ class DateInput(Input): pass return super(DateInput, self)._has_changed(self._format_value(initial), data) -class DateTimeInput(Input): - input_type = 'text' +class DateTimeInput(TextInput): def __init__(self, attrs=None, format=None): super(DateTimeInput, self).__init__(attrs) if format: @@ -462,9 +467,8 @@ class DateTimeInput(Input): pass return super(DateTimeInput, self)._has_changed(self._format_value(initial), data) -class TimeInput(Input): - input_type = 'text' +class TimeInput(TextInput): def __init__(self, attrs=None, format=None): super(TimeInput, self).__init__(attrs) if format: |
