jQuery not decrementing value in Django Inline Formset UpdateView
I'm using this script - https://github.com/elo80ka/django-dynamic-formset/blob/master/src/jquery.formset.js
With this template:
<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>
And it renders this 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>
The specific problem is that the remove
links do not decrement the value of TOTAL_FORMS value=3
<input type="hidden" name="approach_set-TOTAL_FORMS" value="3" id="id_approach_set-TOTAL_FORMS">
The same template is used for the CreateView but works properly. I've compared them against each other and have found no difference.
Thanks for taking a look!
jquery django django-templates
add a comment |
I'm using this script - https://github.com/elo80ka/django-dynamic-formset/blob/master/src/jquery.formset.js
With this template:
<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>
And it renders this 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>
The specific problem is that the remove
links do not decrement the value of TOTAL_FORMS value=3
<input type="hidden" name="approach_set-TOTAL_FORMS" value="3" id="id_approach_set-TOTAL_FORMS">
The same template is used for the CreateView but works properly. I've compared them against each other and have found no difference.
Thanks for taking a look!
jquery django django-templates
add a comment |
I'm using this script - https://github.com/elo80ka/django-dynamic-formset/blob/master/src/jquery.formset.js
With this template:
<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>
And it renders this 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>
The specific problem is that the remove
links do not decrement the value of TOTAL_FORMS value=3
<input type="hidden" name="approach_set-TOTAL_FORMS" value="3" id="id_approach_set-TOTAL_FORMS">
The same template is used for the CreateView but works properly. I've compared them against each other and have found no difference.
Thanks for taking a look!
jquery django django-templates
I'm using this script - https://github.com/elo80ka/django-dynamic-formset/blob/master/src/jquery.formset.js
With this template:
<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>
And it renders this 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>
The specific problem is that the remove
links do not decrement the value of TOTAL_FORMS value=3
<input type="hidden" name="approach_set-TOTAL_FORMS" value="3" id="id_approach_set-TOTAL_FORMS">
The same template is used for the CreateView but works properly. I've compared them against each other and have found no difference.
Thanks for taking a look!
jquery django django-templates
jquery django django-templates
asked Nov 20 at 21:42
user2498975
197
197
add a comment |
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402022%2fjquery-not-decrementing-value-in-django-inline-formset-updateview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53402022%2fjquery-not-decrementing-value-in-django-inline-formset-updateview%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown