Opened 5 years ago
Closed 5 years ago
#31722 closed Uncategorized (invalid)
RangeWidget produces 1 subwidget, itself
Reported by: | Ryan Heard | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | 3.0 |
Severity: | Normal | Keywords: | MultiWidget RangeWidget Widget |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
The RangeWidget cannot be iterated over correctly, as it returns a list of itself for it's subwidgets.
{% for subwidget in form.date_range.subwidgets %} {{ forloop.counter }} {{ subwidget }} {% endfor %}
I would expect that to output "1" then the start widget, then "2" then the end widget. However it only prints "1" and then both widgets, since the subwidget is really the current widget.
Note:
See TracTickets
for help on using tickets.
You need to drill down further to access the child widgets.
form.date_range
is a BoundField.subwidgets
returns the single item list of the BoundWidget wrapping your RangeWidget, which is a MultiWidget subclass. The RangeWidget has awidgets
property containing the child widgets you're after.As per the multi widget docs RangeWidget will add
subwidgets
to the context to be used by the widget template:It's that that can be iterated as you're intending. Please see TicketClosingReasons/UseSupportChannels.