Ticket #15569: fix-nextindex-update2.patch

File fix-nextindex-update2.patch, 2.6 KB (added by Arthur de Jong <arthur@…>, 13 years ago)

second try

  • Django-1.3-rc-1/django/contrib/admin/media/js/inlines.js

    old new  
    1818        $.fn.formset = function(opts) {
    1919                var options = $.extend({}, $.fn.formset.defaults, opts);
    2020                var updateElementIndex = function(el, prefix, ndx) {
    21                         var id_regex = new RegExp("(" + prefix + "-\\d+)");
     21                        var id_regex = new RegExp("(" + prefix + "-(\\d+|__prefix__))");
    2222                        var replacement = prefix + "-" + ndx;
    2323                        if ($(el).attr("for")) {
    2424                                $(el).attr("for", $(el).attr("for").replace(id_regex, replacement));
     
    6060                                    .addClass(options.formCssClass)
    6161                                    .attr("id", options.prefix + "-" + nextIndex);
    6262                                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                                     });
    8763                                if (row.is("tr")) {
    8864                                        // If the forms are laid out in table rows, insert
    8965                                        // the remove button into the last table cell:
     
    9773                                        // last child element of the form's container:
    9874                                        row.children(":first").append('<span><a class="' + options.deleteCssClass + '" href="javascript:void(0)">' + options.deleteText + "</a></span>");
    9975                                }
    100                                 row.find("input,select,textarea,label,a").each(function() {
     76                                row.find("*").each(function() {
    10177                                        updateElementIndex(this, options.prefix, totalForms.val());
    10278                                });
    10379                                // Insert the new form when it has been fully edited
     
    128104                                        // so they remain in sequence:
    129105                                        for (var i=0, formCount=forms.length; i<formCount; i++)
    130106                                        {
    131                                                 $(forms.get(i)).find("input,select,textarea,label,a").each(function() {
     107                                                $(forms.get(i)).find("*").each(function() {
    132108                                                        updateElementIndex(this, options.prefix, i);
    133109                                                });
    134110                                        }
Back to Top