From 6872ce226602555d4566902a5b627ad08acdec94 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 10 Jan 2017 12:30:10 +0100 Subject: [PATCH] Fixed #27712 -- Reallowed Input widget's attrs argument to set the input type. Regression in b52c73008a9d67e9ddbb841872dc15cdd3d6ee01. --- django/forms/widgets.py | 1 + tests/forms_tests/widget_tests/test_input.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 tests/forms_tests/widget_tests/test_input.py diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 4f028d34ad..801067ee38 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -268,6 +268,7 @@ class Input(Widget): def __init__(self, attrs=None): if attrs is not None: + attrs = attrs.copy() self.input_type = attrs.pop('type', self.input_type) super(Input, self).__init__(attrs) diff --git a/tests/forms_tests/widget_tests/test_input.py b/tests/forms_tests/widget_tests/test_input.py new file mode 100644 index 0000000000..e773d94d8a --- /dev/null +++ b/tests/forms_tests/widget_tests/test_input.py @@ -0,0 +1,15 @@ +from django.forms.widgets import Input + +from .base import WidgetTest + + +class InputTests(WidgetTest): + + def test_attrs_with_type(self): + attrs = {'type': 'date'} + widget = Input(attrs) + self.check_html(widget, 'name', 'value', '') + # reuse the same attrs for another widget + self.check_html(Input(attrs), 'name', 'value', '') + attrs['type'] = 'number' # shouldn't change the widget type + self.check_html(widget, 'name', 'value', '')