From 9df8d9c2946bf74288d410e2dc8917493b079b11 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sat, 27 Mar 2010 23:03:12 +0000 Subject: [PATCH] Fixed #13175 - Fixed an off-by-one error in the admin inline JavaScript that resulted in wrong form field prefixes. Thanks DrMeers for the patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12871 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/media/js/inlines.js | 6 +++--- django/contrib/admin/media/js/inlines.min.js | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/django/contrib/admin/media/js/inlines.js b/django/contrib/admin/media/js/inlines.js index 4e397b6d345..7f12c0db3c6 100644 --- a/django/contrib/admin/media/js/inlines.js +++ b/django/contrib/admin/media/js/inlines.js @@ -52,12 +52,12 @@ } addButton.click(function() { var totalForms = $("#id_" + options.prefix + "-TOTAL_FORMS"); - var nextIndex = parseInt(totalForms.val()) + 1; + var nextIndex = parseInt(totalForms.val()); var template = $("#" + options.prefix + "-empty"); var row = template.clone(true).get(0); $(row).removeClass(options.emptyCssClass).removeAttr("id").insertBefore($(template)); $(row).html($(row).html().replace(/__prefix__/g, nextIndex)); - $(row).addClass(options.formCssClass).attr("id", options.prefix + nextIndex); + $(row).addClass(options.formCssClass).attr("id", options.prefix + (nextIndex + 1)); if ($(row).is("TR")) { // If the forms are laid out in table rows, insert // the remove button into the last table cell: @@ -75,7 +75,7 @@ updateElementIndex(this, options.prefix, totalForms.val()); }); // Update number of total forms - $(totalForms).val(nextIndex); + $(totalForms).val(nextIndex + 1); // Hide add button in case we've hit the max, except we want to add infinitely if ((maxForms.val() != 0) && (maxForms.val() <= totalForms.val())) { addButton.parent().hide(); diff --git a/django/contrib/admin/media/js/inlines.min.js b/django/contrib/admin/media/js/inlines.min.js index 7907e36c210..6fc4f82b8d5 100644 --- a/django/contrib/admin/media/js/inlines.min.js +++ b/django/contrib/admin/media/js/inlines.min.js @@ -1,5 +1,5 @@ (function(a){a.fn.formset=function(f){var b=a.extend({},a.fn.formset.defaults,f),l=function(d,e,j){var c=new RegExp("("+e+"-\\d+)");e=e+"-"+j;a(d).attr("for")&&a(d).attr("for",a(d).attr("for").replace(c,e));if(d.id)d.id=d.id.replace(c,e);if(d.name)d.name=d.name.replace(c,e)};f=a("#id_"+b.prefix+"-TOTAL_FORMS").attr("autocomplete","off");var h=a("#id_"+b.prefix+"-MAX_NUM_FORMS").attr("autocomplete","off");f=h.val()==0||h.val()-f.val()>0;a(this).each(function(){a(this).not("."+b.emptyCssClass).addClass(b.formCssClass)}); -if(a(this).length&&f){var i;if(a(this).attr("tagName")=="TR"){f=this.eq(0).children().length;a(this).parent().append(''+b.addText+"");i=a(this).parent().find("tr:last a")}else{a(this).filter(":last").after('
'+b.addText+"
");i=a(this).filter(":last").next().find("a")}i.click(function(){var d=a("#id_"+b.prefix+"-TOTAL_FORMS"),e=parseInt(d.val())+ -1,j=a("#"+b.prefix+"-empty"),c=j.clone(true).get(0);a(c).removeClass(b.emptyCssClass).removeAttr("id").insertBefore(a(j));a(c).html(a(c).html().replace(/__prefix__/g,e));a(c).addClass(b.formCssClass).attr("id",b.prefix+e);if(a(c).is("TR"))a(c).children(":last").append('
'+b.deleteText+"
");else a(c).is("UL")||a(c).is("OL")?a(c).append('
  • '+b.deleteText+"
  • "):a(c).children(":first").append(''+b.deleteText+"");a(c).find("input,select,textarea,label,a").each(function(){l(this,b.prefix,d.val())});a(d).val(e);h.val()!=0&&h.val()<=d.val()&&i.parent().hide();a(c).find("a."+b.deleteCssClass).click(function(){var g=a(this).parents("."+b.formCssClass);g.remove();b.removed&&b.removed(g);g=a("."+b.formCssClass);a("#id_"+b.prefix+"-TOTAL_FORMS").val(g.length);if(h.val()==0||h.val()>=g.length)i.parent().show();for(var k=0,m=g.length;k'+b.addText+"");i=a(this).parent().find("tr:last a")}else{a(this).filter(":last").after('");i=a(this).filter(":last").next().find("a")}i.click(function(){var d=a("#id_"+b.prefix+"-TOTAL_FORMS"),e=parseInt(d.val()), +j=a("#"+b.prefix+"-empty"),c=j.clone(true).get(0);a(c).removeClass(b.emptyCssClass).removeAttr("id").insertBefore(a(j));a(c).html(a(c).html().replace(/__prefix__/g,e));a(c).addClass(b.formCssClass).attr("id",b.prefix+(parseInt(e)+1));if(a(c).is("TR"))a(c).children(":last").append('
    '+b.deleteText+"
    ");else a(c).is("UL")||a(c).is("OL")?a(c).append('
  • '+b.deleteText+"
  • "): +a(c).children(":first").append(''+b.deleteText+"");a(c).find("input,select,textarea,label,a").each(function(){l(this,b.prefix,d.val())});a(d).val(e+1);h.val()!=0&&h.val()<=d.val()&&i.parent().hide();a(c).find("a."+b.deleteCssClass).click(function(){var g=a(this).parents("."+b.formCssClass);g.remove();b.removed&&b.removed(g);g=a("."+b.formCssClass);a("#id_"+b.prefix+"-TOTAL_FORMS").val(g.length);if(h.val()==0||h.val()>=g.length)i.parent().show(); +for(var k=0,m=g.length;k