Fixed #14193: prepopulated_fields javascript now concatenates in correct order. Thanks to bmihelac for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14122 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Andrew Godwin 2010-10-10 09:57:23 +00:00
parent 941318fcee
commit c236d5e44d
5 changed files with 17 additions and 11 deletions

View File

@ -4,7 +4,7 @@
Depends on urlify.js Depends on urlify.js
Populates a selected field with the values of the dependent fields, Populates a selected field with the values of the dependent fields,
URLifies and shortens the string. 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 maxLength - maximum length of the URLify'd string
*/ */
return this.each(function() { return this.each(function() {
@ -20,15 +20,15 @@
if (field.data('_changed') == true) return; if (field.data('_changed') == true) return;
var values = []; var values = [];
dependencies.each(function() { $.each(dependencies, function(i, field) {
if ($(this).val().length > 0) { if ($(field).val().length > 0) {
values.push($(this).val()); values.push($(field).val());
} }
}); })
field.val(URLify(values.join(' '), maxLength)); field.val(URLify(values.join(' '), maxLength));
}; };
dependencies.keyup(populate).change(populate).focus(populate); $(dependencies.join(',')).keyup(populate).change(populate).focus(populate);
}); });
}; };
})(django.jQuery); })(django.jQuery);

View File

@ -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 File

@ -53,7 +53,10 @@
var field = $(this); var field = $(this);
var input = field.find('input, select, textarea'); var input = field.find('input, select, textarea');
var dependency_list = input.data('dependency_list') || []; 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) { if (dependencies.length) {
input.prepopulate(dependencies, input.attr('maxlength')); input.prepopulate(dependencies, input.attr('maxlength'));
} }

View File

@ -99,7 +99,10 @@
var field = $(this); var field = $(this);
var input = field.find('input, select, textarea'); var input = field.find('input, select, textarea');
var dependency_list = input.data('dependency_list') || []; 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) { if (dependencies.length) {
input.prepopulate(dependencies, input.attr('maxlength')); input.prepopulate(dependencies, input.attr('maxlength'));
} }

View File

@ -17,7 +17,7 @@
$('.empty-form .{{ field.field.name }}').addClass('prepopulated_field'); $('.empty-form .{{ field.field.name }}').addClass('prepopulated_field');
$(field.id).data('dependency_list', field['dependency_list']) $(field.id).data('dependency_list', field['dependency_list'])
.prepopulate($(field['dependency_ids'].join(',')), field.maxLength); .prepopulate(field['dependency_ids'], field.maxLength);
{% endfor %} {% endfor %}
})(django.jQuery); })(django.jQuery);
</script> </script>