Permalink
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...
1 parent c4956d1 commit be190d1913b3e95cf13bc99d7674facfcfaec41c @andrewgodwin andrewgodwin committed Oct 10, 2010
@@ -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);
Oops, something went wrong.
@@ -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'));
}
@@ -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'));
}
@@ -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>

0 comments on commit be190d1

Please sign in to comment.