Я использую этот скрипт - https://github.com/elo80ka/django-dynamic-formset/blob/master/src/jquery.formset.js
С этим шаблоном:
<div id="approach_form" class="form-control pl-4 pt-2">
{% for formset in inlines %}
<table>
{% for form in formset %}
{{ form.id }}
{{ form.errors }}
<tr>
<td>{{ form.approach_type }}</td>
<td>{{ form.number }}</td>
<td>{% if form.instance.pk %}{{ form.DELETE }}{% endif %}</td>
</tr>
{% endfor %}
</table>
{{ formset.management_form }}
{% endfor %}
</div>
И он отображает этот HTML:
<div id="approach_form" class="form-control pl-4 pt-2">
<table>
<input type="hidden" name="approach_set-0-id" value="25" id="id_approach_set-0-id">
<tbody><tr class="approach-formset">
<td><select name="approach_set-0-approach_type" id="id_approach_set-0-approach_type">
<option value="">---------</option>
<option value="ILS">ILS</option>
<option value="CATII">CAT II</option>
</select></td>
<td><input type="number" name="approach_set-0-number" value="2" min="0" id="id_approach_set-0-number"></td>
<td><input type="hidden" name="approach_set-0-DELETE" id="id_approach_set-0-DELETE"><a class="delete-row" href="javascript:void(0)">Remove</a></td>
</tr>
<input type="hidden" name="approach_set-1-id" value="24" id="id_approach_set-1-id">
<tr class="approach-formset">
<td><select name="approach_set-1-approach_type" id="id_approach_set-1-approach_type">
<option value="">---------</option>
<option value="ILS" selected="">ILS</option>
<option value="CATII">CAT II</option>
<option value="CATIII">CAT III</option>
</select></td>
<td><input type="number" name="approach_set-1-number" value="1" min="0" id="id_approach_set-1-number"></td>
<td><input type="hidden" name="approach_set-1-DELETE" id="id_approach_set-1-DELETE"><a class="delete-row" href="javascript:void(0)">Remove</a></td>
</tr>
<input type="hidden" name="approach_set-2-id" value="26" id="id_approach_set-2-id">
<tr class="approach-formset">
<td><select name="approach_set-2-approach_type" id="id_approach_set-2-approach_type">
<option value="">---------</option>
<option value="ILS">ILS</option>
<option value="CATII">CAT II</option>
</select></td>
<td><input type="number" name="approach_set-2-number" value="3" min="0" id="id_approach_set-2-number"></td>
<td><input type="hidden" name="approach_set-2-DELETE" id="id_approach_set-2-DELETE"><a class="delete-row" href="javascript:void(0)">Remove</a></td>
</tr>
<tr class="approach-formset-add"><td colspan="3"><a class="add-row" href="javascript:void(0)">Add</a></td></tr></tbody></table>
<input type="hidden" name="approach_set-TOTAL_FORMS" value="3" id="id_approach_set-TOTAL_FORMS"><input type="hidden" name="approach_set-INITIAL_FORMS" value="3" id="id_approach_set-INITIAL_FORMS"><input type="hidden" name="approach_set-MIN_NUM_FORMS" value="0" id="id_approach_set-MIN_NUM_FORMS"><input type="hidden" name="approach_set-MAX_NUM_FORMS" value="4" id="id_approach_set-MAX_NUM_FORMS">
</div>
Конкретная проблемаявляется то, что ссылки remove
не уменьшают значение значения TOTAL_FORMS = 3 <input type="hidden" name="approach_set-TOTAL_FORMS" value="3" id="id_approach_set-TOTAL_FORMS">
Тот же шаблон используется для CreateView, но работает должным образом.Я сравнил их друг с другом и не нашел никакой разницы.
Спасибо, что взглянули!