#9230: Iterating over checkboxes in CheckboxSelectMultiple should be possible
-----------------------------+---------------------------------------
Reporter: mtredinnick | Owner: mtredinnick
Type: New feature | Status: closed
Component: Forms | Version: 1.0
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------
Comment (by gabn88):
This is my first post here, so sorry if I'm doing it wrong.
I'm trying to iterate over my checkboxes (using Django 1.7.7) where I'm
using an ModelFormSet to generate multiple forms.
My original code is:
{{{
{%if field.name == "repeat_weekday" %}
<td>{{field}}<td>
{% endif %}
}}}
Now I have made:
{{{
{% for choice, choice_label in field.field.widget.choices %}
<td> <input checked={{choice.checked}}
id="id_form-0-repeat_weekday_0" name="form-0-repeat_weekday"
type="checkbox" value="{{ choice }}"> {{choice_label}} </td>
{% endfor %}
}}}
but I don't know how to find the = checked and id and name via the field.
Easier would IMO be to do something like the thing below (and I would say
that would be a genuine fix of the issue in this ticket):
{{{
{% for checkbox, label in field.checkboxes %}
{{ checkbox }} <!-- Renders the checkbox completely
{{ label }} <!-- Renders the label completely
{% endfor %}
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/9230#comment:14>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/069.7717d553981cf1cc5bdb9afeb9f8859e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.