diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2016-07-21 22:05:17 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-08-04 19:16:54 -0400 |
| commit | 50e299dbfbbfd796e63e7e13b4566cf69d2c4acb (patch) | |
| tree | e099779317d600e23cdf45f2e7c0b5a1e69791d8 /django/forms/widgets.py | |
| parent | ebed9ee8d5e4268d9393261633b2c23cffd426fc (diff) | |
Fixed #26928 -- Changed forms' checked attribute to HTML5 boolean style.
Diffstat (limited to 'django/forms/widgets.py')
| -rw-r--r-- | django/forms/widgets.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/django/forms/widgets.py b/django/forms/widgets.py index ec076398cc..224bd3de4d 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -481,9 +481,7 @@ class CheckboxInput(Widget): self.check_test = boolean_check if check_test is None else check_test def render(self, name, value, attrs=None): - final_attrs = self.build_attrs(attrs, type='checkbox', name=name) - if self.check_test(value): - final_attrs['checked'] = 'checked' + final_attrs = self.build_attrs(attrs, type='checkbox', name=name, checked=self.check_test(value)) if not (value is True or value is False or value is None or value == ''): # Only add the 'value' attribute if a value is non-empty. final_attrs['value'] = force_text(value) @@ -646,9 +644,13 @@ class ChoiceInput(SubWidget): def tag(self, attrs=None): attrs = attrs or self.attrs - final_attrs = dict(attrs, type=self.input_type, name=self.name, value=self.choice_value) - if self.is_checked(): - final_attrs['checked'] = 'checked' + final_attrs = dict( + attrs, + type=self.input_type, + name=self.name, + value=self.choice_value, + checked=self.is_checked(), + ) return format_html('<input{} />', flatatt(final_attrs)) @property |
