Skip to content

Commit

Permalink
Fixed #14303 -- Ensure that the ids created for new inlines are uniqu…
Browse files Browse the repository at this point in the history
…e after interstitial deletions have occurred. Thanks to m0nonoke for the report, and Julien Phalip for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15422 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
freakboy3742 committed Feb 5, 2011
1 parent baef1cf commit 7f65c33
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions django/contrib/admin/media/js/inlines.js
Expand Up @@ -31,6 +31,7 @@
}
};
var totalForms = $("#id_" + options.prefix + "-TOTAL_FORMS").attr("autocomplete", "off");
var nextIndex = parseInt(totalForms.val());
var maxForms = $("#id_" + options.prefix + "-MAX_NUM_FORMS").attr("autocomplete", "off");
// only show the add button if we are allowed to add more items,
// note that max_num = None translates to a blank string.
Expand All @@ -53,12 +54,12 @@
}
addButton.click(function() {
var totalForms = $("#id_" + options.prefix + "-TOTAL_FORMS");
var nextIndex = parseInt(totalForms.val());
var template = $("#" + options.prefix + "-empty");
var row = template.clone(true);
row.removeClass(options.emptyCssClass)
.addClass(options.formCssClass)
.attr("id", options.prefix + "-" + nextIndex);
nextIndex += 1;
row.find("*")
.filter(function() {
var el = $(this);
Expand Down Expand Up @@ -94,7 +95,7 @@
// Insert the new form when it has been fully edited
row.insertBefore($(template));
// Update number of total forms
$(totalForms).val(nextIndex + 1);
$(totalForms).val(parseInt(totalForms.val()) + 1);
// Hide add button in case we've hit the max, except we want to add infinitely
if ((maxForms.val() != '') && (maxForms.val()-totalForms.val()) <= 0) {
addButton.parent().hide();
Expand Down
10 changes: 5 additions & 5 deletions django/contrib/admin/media/js/inlines.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion django/contrib/admin/media/js/prepopulate.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7f65c33

Please sign in to comment.