#26927 closed Bug (fixed)
Subwidgets not passed required and disabled attributes in BoundField.__iter__()
| Reported by: | Jon Dufresne | Owned by: | nobody |
|---|---|---|---|
| Component: | Forms | Version: | dev |
| Severity: | Normal | Keywords: | 1.10 |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Similar in spirit to #20555.
I have a form with a field like:
my_field = forms.ChoiceField(widget=forms.RadioSelect, choice=get_choices(), disabled=True)
The field's radio buttons are rendered in a template by iterating over the BoundField:
{% for choice in form.my_field %}
{{ choice.tag }}
{% endfor %}
The rendered HTML input is not disabled. This is because BoundField.__iter__() does not pass the required and disabled attributes to subwidgets.
Contrast this with BoundField.as_widget() where the values are passed.
Perhaps this attribute building should be factored to a utility function out and shared across these two functions.
Change History (5)
comment:1 by , 9 years ago
| Has patch: | set |
|---|
comment:2 by , 9 years ago
| Keywords: | 1.10 added |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:3 by , 9 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Note:
See TracTickets
for help on using tickets.
PR
I think this PR, or at least parts of it, should be considered for 1.10. The
requiredattribute is newly introduced in 1.10 with the following concerns:requiredattribute will be carried over during iteration. (From this one might also assumedisabled.)CheckboxSelectMultiplewidget will behave incorrectly with therequiredattribute. When browsers see multiple checkboxes with the samenameattribute markedrequiredthe browser requires all checkboxes checked instead of at least one. This validation contradicts Django's server side validation of requiring at least one item for multiple choice fields. This will make Django forms usingCheckboxSelectMultipleappear broken.