Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.2.X] Fixed #14193: prepopulated_fields javascript now concatenates…

… in correct order. Thanks to bmihelac for the patch.

Backport of [14122] from trunk

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14123 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit be190d1913b3e95cf13bc99d7674facfcfaec41c 1 parent c4956d1
@andrewgodwin andrewgodwin authored
View
14 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);
View
2  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);
View
5 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'));
}
View
5 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'));
}
View
2  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);
</script>
Please sign in to comment.
Something went wrong with that request. Please try again.