1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #26927 -- Made subwidget iteration pass disabled and required attributes.

This commit is contained in:
Jon Dufresne
2016-07-21 17:16:22 -07:00
committed by Tim Graham
parent aad46c3e37
commit ac3aaaa740
4 changed files with 42 additions and 25 deletions

View File

@@ -51,6 +51,7 @@ class BoundField(object):
"""
id_ = self.field.widget.attrs.get('id') or self.auto_id
attrs = {'id': id_} if id_ else {}
attrs = self.build_widget_attrs(attrs)
for subwidget in self.field.widget.subwidgets(self.html_name, self.value(), attrs):
yield subwidget
@@ -85,10 +86,7 @@ class BoundField(object):
widget.is_localized = True
attrs = attrs or {}
if not widget.is_hidden and self.field.required and self.form.use_required_attribute:
attrs['required'] = True
if self.field.disabled:
attrs['disabled'] = True
attrs = self.build_widget_attrs(attrs, widget)
auto_id = self.auto_id
if auto_id and 'id' not in attrs and 'id' not in widget.attrs:
if not only_initial:
@@ -227,3 +225,13 @@ class BoundField(object):
widget = self.field.widget
id_ = widget.attrs.get('id') or self.auto_id
return widget.id_for_label(id_)
def build_widget_attrs(self, attrs, widget=None):
if not widget:
widget = self.field.widget
attrs = dict(attrs) # Copy attrs to avoid modifying the argument.
if not widget.is_hidden and self.field.required and self.form.use_required_attribute:
attrs['required'] = True
if self.field.disabled:
attrs['disabled'] = True
return attrs