diff --git a/django/contrib/admin/media/js/inlines.js b/django/contrib/admin/media/js/inlines.js index cf790235c0..c48c1f5c57 100644 --- a/django/contrib/admin/media/js/inlines.js +++ b/django/contrib/admin/media/js/inlines.js @@ -58,8 +58,7 @@ var row = template.clone(true); row.removeClass(options.emptyCssClass) .addClass(options.formCssClass) - .attr("id", options.prefix + "-" + nextIndex) - .insertBefore($(template)); + .attr("id", options.prefix + "-" + nextIndex); row.find("*") .filter(function() { var el = $(this); @@ -92,6 +91,8 @@ row.find("input,select,textarea,label,a").each(function() { updateElementIndex(this, options.prefix, totalForms.val()); }); + // Insert the new form when it has been fully edited + row.insertBefore($(template)); // Update number of total forms $(totalForms).val(nextIndex + 1); // Hide add button in case we've hit the max, except we want to add infinitely diff --git a/django/contrib/admin/media/js/inlines.min.js b/django/contrib/admin/media/js/inlines.min.js index 9e0926fd1a..cf1c708271 100644 --- a/django/contrib/admin/media/js/inlines.min.js +++ b/django/contrib/admin/media/js/inlines.min.js @@ -1,6 +1,6 @@ -(function(a){a.fn.formset=function(g){var b=a.extend({},a.fn.formset.defaults,g),l=function(e,f,j){var d=new RegExp("("+f+"-\\d+)");f=f+"-"+j;a(e).attr("for")&&a(e).attr("for",a(e).attr("for").replace(d,f));if(e.id)e.id=e.id.replace(d,f);if(e.name)e.name=e.name.replace(d,f)};g=a("#id_"+b.prefix+"-TOTAL_FORMS").attr("autocomplete","off");var h=a("#id_"+b.prefix+"-MAX_NUM_FORMS").attr("autocomplete","off");g=h.val()==""||h.val()-g.val()>0;a(this).each(function(){a(this).not("."+b.emptyCssClass).addClass(b.formCssClass)}); +(function(a){a.fn.formset=function(g){var b=a.extend({},a.fn.formset.defaults,g),l=function(e,f,j){var d=RegExp("("+f+"-\\d+)");f=f+"-"+j;a(e).attr("for")&&a(e).attr("for",a(e).attr("for").replace(d,f));if(e.id)e.id=e.id.replace(d,f);if(e.name)e.name=e.name.replace(d,f)};g=a("#id_"+b.prefix+"-TOTAL_FORMS").attr("autocomplete","off");var h=a("#id_"+b.prefix+"-MAX_NUM_FORMS").attr("autocomplete","off");g=h.val()==""||h.val()-g.val()>0;a(this).each(function(){a(this).not("."+b.emptyCssClass).addClass(b.formCssClass)}); if(a(this).length&&g){var i;if(a(this).attr("tagName")=="TR"){g=this.eq(0).children().length;a(this).parent().append('