jQuery不会递减Django Inline Formset UpdateView中的值

时间:2018-11-20 21:42:49

标签: jquery django django-templates

我正在使用此脚本-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,但可以正常工作。我将它们相互比较,没有发现任何区别。

感谢您的光临!

0 个答案:

没有答案