diff --git a/django/contrib/admin/media/js/prepopulate.js b/django/contrib/admin/media/js/prepopulate.js index 09483bbf04..24f24f95a8 100644 --- a/django/contrib/admin/media/js/prepopulate.js +++ b/django/contrib/admin/media/js/prepopulate.js @@ -4,7 +4,7 @@ Depends on urlify.js Populates a selected field with the values of the dependent fields, URLifies and shortens the string. - dependencies - selected jQuery object of dependent fields + dependencies - array of dependent fields id's maxLength - maximum length of the URLify'd string */ return this.each(function() { @@ -20,15 +20,15 @@ if (field.data('_changed') == true) return; var values = []; - dependencies.each(function() { - if ($(this).val().length > 0) { - values.push($(this).val()); - } - }); + $.each(dependencies, function(i, field) { + if ($(field).val().length > 0) { + values.push($(field).val()); + } + }) field.val(URLify(values.join(' '), maxLength)); }; - dependencies.keyup(populate).change(populate).focus(populate); + $(dependencies.join(',')).keyup(populate).change(populate).focus(populate); }); }; })(django.jQuery); diff --git a/django/contrib/admin/media/js/prepopulate.min.js b/django/contrib/admin/media/js/prepopulate.min.js index f1ca297b80..98fdc93d2f 100644 --- a/django/contrib/admin/media/js/prepopulate.min.js +++ b/django/contrib/admin/media/js/prepopulate.min.js @@ -1 +1 @@ -(function(b){b.fn.prepopulate=function(d,f){return this.each(function(){var a=b(this);a.data("_changed",false);a.change(function(){a.data("_changed",true)});var c=function(){if(a.data("_changed")!=true){var e=[];d.each(function(){b(this).val().length>0&&e.push(b(this).val())});a.val(URLify(e.join(" "),f))}};d.keyup(c).change(c).focus(c)})}})(django.jQuery); +(function(a){a.fn.prepopulate=function(d,g){return this.each(function(){var b=a(this);b.data("_changed",false);b.change(function(){b.data("_changed",true)});var c=function(){if(b.data("_changed")!=true){var e=[];a.each(d,function(h,f){a(f).val().length>0&&e.push(a(f).val())});b.val(URLify(e.join(" "),g))}};a(d.join(",")).keyup(c).change(c).focus(c)})}})(django.jQuery); \ No newline at end of file diff --git a/django/contrib/admin/templates/admin/edit_inline/stacked.html b/django/contrib/admin/templates/admin/edit_inline/stacked.html index 1ecb790b5e..f1e338f9a6 100644 --- a/django/contrib/admin/templates/admin/edit_inline/stacked.html +++ b/django/contrib/admin/templates/admin/edit_inline/stacked.html @@ -53,7 +53,10 @@ var field = $(this); var input = field.find('input, select, textarea'); var dependency_list = input.data('dependency_list') || []; - var dependencies = row.find(dependency_list.join(',')).find('input, select, textarea'); + var dependencies = []; + $.each(dependency_list, function(i, field_name) { + dependencies.push('#' + row.find(field_name).find('input, select, textarea').attr('id')); + }); if (dependencies.length) { input.prepopulate(dependencies, input.attr('maxlength')); } diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html index 35dea391af..a5b1a899f5 100644 --- a/django/contrib/admin/templates/admin/edit_inline/tabular.html +++ b/django/contrib/admin/templates/admin/edit_inline/tabular.html @@ -99,7 +99,10 @@ var field = $(this); var input = field.find('input, select, textarea'); var dependency_list = input.data('dependency_list') || []; - var dependencies = row.find(dependency_list.join(',')).find('input, select, textarea'); + var dependencies = []; + $.each(dependency_list, function(i, field_name) { + dependencies.push('#' + row.find(field_name).find('input, select, textarea').attr('id')); + }); if (dependencies.length) { input.prepopulate(dependencies, input.attr('maxlength')); } diff --git a/django/contrib/admin/templates/admin/prepopulated_fields_js.html b/django/contrib/admin/templates/admin/prepopulated_fields_js.html index 4aa6380313..43ef5ba071 100644 --- a/django/contrib/admin/templates/admin/prepopulated_fields_js.html +++ b/django/contrib/admin/templates/admin/prepopulated_fields_js.html @@ -17,7 +17,7 @@ $('.empty-form .{{ field.field.name }}').addClass('prepopulated_field'); $(field.id).data('dependency_list', field['dependency_list']) - .prepopulate($(field['dependency_ids'].join(',')), field.maxLength); + .prepopulate(field['dependency_ids'], field.maxLength); {% endfor %} })(django.jQuery);