Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#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 Jon Dufresne, 8 years ago

Has patch: set

PR

I think this PR, or at least parts of it, should be considered for 1.10. The required attribute is newly introduced in 1.10 with the following concerns:

  1. The documentation about looping over subwidgets suggests the required attribute will be carried over during iteration. (From this one might also assume disabled.)
  2. IMO more importantly, as noted in the PR, the CheckboxSelectMultiple widget will behave incorrectly with the required attribute. When browsers see multiple checkboxes with the same name attribute marked required the 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 using CheckboxSelectMultiple appear broken.

comment:2 by Tim Graham, 8 years ago

Keywords: 1.10 added
Triage Stage: UnreviewedAccepted

comment:3 by Tim Graham, 8 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In ac3aaaa:

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

comment:5 by Tim Graham <timograham@…>, 8 years ago

In 6a3f31fa:

[1.10.x] Fixed #26927 -- Made subwidget iteration pass disabled and required attributes.

Backport of ac3aaaa740dcf9c6efd2f88ee9219c1924c7695e from master

Note: See TracTickets for help on using tickets.
Back to Top