Ticket #15569: fix-nextindex-update2.patch
File fix-nextindex-update2.patch, 2.6 KB (added by , 14 years ago) |
---|
-
Django-1.3-rc-1/django/contrib/admin/media/js/inlines.js
old new 18 18 $.fn.formset = function(opts) { 19 19 var options = $.extend({}, $.fn.formset.defaults, opts); 20 20 var updateElementIndex = function(el, prefix, ndx) { 21 var id_regex = new RegExp("(" + prefix + "- \\d+)");21 var id_regex = new RegExp("(" + prefix + "-(\\d+|__prefix__))"); 22 22 var replacement = prefix + "-" + ndx; 23 23 if ($(el).attr("for")) { 24 24 $(el).attr("for", $(el).attr("for").replace(id_regex, replacement)); … … 60 60 .addClass(options.formCssClass) 61 61 .attr("id", options.prefix + "-" + nextIndex); 62 62 nextIndex += 1; 63 row.find("*")64 .filter(function() {65 var el = $(this);66 return el.attr("id") && el.attr("id").search(/__prefix__/) >= 0;67 }).each(function() {68 var el = $(this);69 el.attr("id", el.attr("id").replace(/__prefix__/g, nextIndex));70 })71 .end()72 .filter(function() {73 var el = $(this);74 return el.attr("name") && el.attr("name").search(/__prefix__/) >= 0;75 }).each(function() {76 var el = $(this);77 el.attr("name", el.attr("name").replace(/__prefix__/g, nextIndex));78 })79 .end()80 .filter(function() {81 var el = $(this);82 return el.attr("for") && el.attr("for").search(/__prefix__/) >= 0;83 }).each(function() {84 var el = $(this);85 el.attr("for", el.attr("for").replace(/__prefix__/g, nextIndex));86 });87 63 if (row.is("tr")) { 88 64 // If the forms are laid out in table rows, insert 89 65 // the remove button into the last table cell: … … 97 73 // last child element of the form's container: 98 74 row.children(":first").append('<span><a class="' + options.deleteCssClass + '" href="javascript:void(0)">' + options.deleteText + "</a></span>"); 99 75 } 100 row.find(" input,select,textarea,label,a").each(function() {76 row.find("*").each(function() { 101 77 updateElementIndex(this, options.prefix, totalForms.val()); 102 78 }); 103 79 // Insert the new form when it has been fully edited … … 128 104 // so they remain in sequence: 129 105 for (var i=0, formCount=forms.length; i<formCount; i++) 130 106 { 131 $(forms.get(i)).find(" input,select,textarea,label,a").each(function() {107 $(forms.get(i)).find("*").each(function() { 132 108 updateElementIndex(this, options.prefix, i); 133 109 }); 134 110 }