summaryrefslogtreecommitdiff
path: root/django/forms/boundfield.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2016-07-21 17:16:22 -0700
committerTim Graham <timograham@gmail.com>2016-08-01 10:36:17 -0400
commitac3aaaa740dcf9c6efd2f88ee9219c1924c7695e (patch)
tree72e8a094b6f88f60e80397eaf00ce52feb46ed6f /django/forms/boundfield.py
parentaad46c3e370e105f9117a337924090d05f1b001d (diff)
Fixed #26927 -- Made subwidget iteration pass disabled and required attributes.
Diffstat (limited to 'django/forms/boundfield.py')
-rw-r--r--django/forms/boundfield.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/django/forms/boundfield.py b/django/forms/boundfield.py
index 4867e72deb..df3de5848e 100644
--- a/django/forms/boundfield.py
+++ b/django/forms/boundfield.py
@@ -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