I am trying to use Django cycle to make my css class have the current table row number in it. I'm trying the following:
{{ formset.management_form }}
{% for form in formset %}
<tr class="{% cycle 'row1' 'row2' 'row3' %} formset_row">
{% for field in form.visible_fields %}
<td>
{# Include the hidden fields in the form #}
{% if forloop.first %}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
{% endif %}
{{ field.errors.as_ul }}
{{ field }}
</td>
{% endfor %}
</tr>
{% endfor %}
Where my rows are added dynamically using jquery.formset.js https://gist.github.com/vandorjw/f884f0d51db3e7caaecd
For some reason this just gives me
<tr class="row1 formset_row">...</tr>
<tr class="row1 formset_row">...</tr>
<tr class="row1 formset_row">...</tr>
<tr class="row1 formset_row">...</tr>
...
Why isn't this working?
From what I understand this will give me
row1 row2 row3 row1 row2 row3 row1...
How can I make this continue counting...
row1 row2 row3 row4 row5 row6 row7...
I'm not sure why it's not working, but if you want it to continue counting along with the entire loop, you can use
class="row{{forloop.counter}}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With