diff --git a/django/contrib/admin/static/admin/js/inlines.js b/django/contrib/admin/static/admin/js/inlines.js index c8eb9973920..a4a328ad010 100644 --- a/django/contrib/admin/static/admin/js/inlines.js +++ b/django/contrib/admin/static/admin/js/inlines.js @@ -145,10 +145,10 @@ // Tabular inlines --------------------------------------------------------- - $.fn.tabularFormset = function(options) { + $.fn.tabularFormset = function(selector, options) { var $rows = $(this); var alternatingRows = function(row) { - $($rows.selector).not(".add-row").removeClass("row1 row2") + $(selector).not(".add-row").removeClass("row1 row2") .filter(":even").addClass("row1").end() .filter(":odd").addClass("row2"); }; @@ -212,10 +212,10 @@ }; // Stacked inlines --------------------------------------------------------- - $.fn.stackedFormset = function(options) { + $.fn.stackedFormset = function(selector, options) { var $rows = $(this); var updateInlineLabel = function(row) { - $($rows.selector).find(".inline_label").each(function(i) { + $(selector).find(".inline_label").each(function(i) { var count = i + 1; $(this).html($(this).html().replace(/(#\d+)/g, "#" + count)); }); @@ -281,13 +281,16 @@ $(document).ready(function() { $(".js-inline-admin-formset").each(function() { var data = $(this).data(), - inlineOptions = data.inlineFormset; + inlineOptions = data.inlineFormset, + selector; switch(data.inlineType) { case "stacked": - $(inlineOptions.name + "-group .inline-related").stackedFormset(inlineOptions.options); + selector = inlineOptions.name + "-group .inline-related"; + $(selector).stackedFormset(selector, inlineOptions.options); break; case "tabular": - $(inlineOptions.name + "-group .tabular.inline-related tbody:first > tr").tabularFormset(inlineOptions.options); + selector = inlineOptions.name + "-group .tabular.inline-related tbody:first > tr"; + $(selector).tabularFormset(selector, inlineOptions.options); break; } }); diff --git a/django/contrib/admin/static/admin/js/inlines.min.js b/django/contrib/admin/static/admin/js/inlines.min.js index de82c24d3f1..04090a353d7 100644 --- a/django/contrib/admin/static/admin/js/inlines.min.js +++ b/django/contrib/admin/static/admin/js/inlines.min.js @@ -1,13 +1,13 @@ -var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(b,c,a){b instanceof String&&(b=String(b));for(var d=b.length,f=0;f'+a.addText+""),k=c.find("tr:last a")):(d.filter(":last").after('
'+a.addText+"
"),k=d.filter(":last").next().find("a")));k.click(function(c){c.preventDefault();c=b("#"+a.prefix+"-empty"); -var d=c.clone(!0);d.removeClass(a.emptyCssClass).addClass(a.formCssClass).attr("id",a.prefix+"-"+e);d.is("tr")?d.children(":last").append('
'+a.deleteText+"
"):d.is("ul")||d.is("ol")?d.append('
  • '+a.deleteText+"
  • "):d.children(":first").append(''+a.deleteText+"");d.find("*").each(function(){f(this,a.prefix,g.val())});d.insertBefore(b(c)); -b(g).val(parseInt(g.val(),10)+1);e+=1;""!==h.val()&&0>=h.val()-g.val()&&k.parent().hide();d.find("a."+a.deleteCssClass).click(function(c){c.preventDefault();d.remove();--e;a.removed&&a.removed(d);b(document).trigger("formset:removed",[d,a.prefix]);c=b("."+a.formCssClass);b("#id_"+a.prefix+"-TOTAL_FORMS").val(c.length);(""===h.val()||0 tr").tabularFormset(a.options)}})})})(django.jQuery); +(function(b){b.fn.formset=function(d){var a=b.extend({},b.fn.formset.defaults,d),c=b(this);d=c.parent();var f=function(a,e,d){var c=new RegExp("("+e+"-(\\d+|__prefix__))");e=e+"-"+d;b(a).prop("for")&&b(a).prop("for",b(a).prop("for").replace(c,e));a.id&&(a.id=a.id.replace(c,e));a.name&&(a.name=a.name.replace(c,e))},g=b("#id_"+a.prefix+"-TOTAL_FORMS").prop("autocomplete","off"),h=parseInt(g.val(),10),e=b("#id_"+a.prefix+"-MAX_NUM_FORMS").prop("autocomplete","off"),m=""===e.val()||0'+a.addText+""),l=d.find("tr:last a")):(c.filter(":last").after('"),l=c.filter(":last").next().find("a")));l.click(function(d){d.preventDefault();d=b("#"+a.prefix+"-empty"); +var c=d.clone(!0);c.removeClass(a.emptyCssClass).addClass(a.formCssClass).attr("id",a.prefix+"-"+h);c.is("tr")?c.children(":last").append('
    '+a.deleteText+"
    "):c.is("ul")||c.is("ol")?c.append('
  • '+a.deleteText+"
  • "):c.children(":first").append(''+a.deleteText+"");c.find("*").each(function(){f(this,a.prefix,g.val())});c.insertBefore(b(d)); +b(g).val(parseInt(g.val(),10)+1);h+=1;""!==e.val()&&0>=e.val()-g.val()&&l.parent().hide();c.find("a."+a.deleteCssClass).click(function(d){d.preventDefault();c.remove();--h;a.removed&&a.removed(c);b(document).trigger("formset:removed",[c,a.prefix]);d=b("."+a.formCssClass);b("#id_"+a.prefix+"-TOTAL_FORMS").val(d.length);(""===e.val()||0 tr",b(d).tabularFormset(d,a.options)}})})})(django.jQuery); diff --git a/js_tests/admin/inlines.test.js b/js_tests/admin/inlines.test.js index 2ff6a145779..7b7097939c4 100644 --- a/js_tests/admin/inlines.test.js +++ b/js_tests/admin/inlines.test.js @@ -11,7 +11,7 @@ QUnit.module('admin.inlines: tabular formsets', { $('#qunit-fixture').append($('#tabular-formset').text()); this.table = $('table.inline'); this.inlineRow = this.table.find('tr'); - that.inlineRow.tabularFormset({ + that.inlineRow.tabularFormset('table.inline tr', { prefix: 'first', addText: that.addText, deleteText: 'Remove' @@ -60,7 +60,7 @@ QUnit.test('existing add button', function(assert) { this.inlineRow = this.table.find('tr'); this.table.append(''); var addButton = this.table.find('.add-button'); - this.inlineRow.tabularFormset({ + this.inlineRow.tabularFormset('table.inline tr', { prefix: 'first', deleteText: 'Remove', addButton: addButton