From 7c04f8e200043384bf0c3ed07e6caf7b5c3324d4 Mon Sep 17 00:00:00 2001
From: Bojan Mihelac <bmihelac@mihelac.org>
Date: Mon, 30 Aug 2010 16:25:34 +0200
Subject: [PATCH] Fix for #14193, respect given order when creating prepopulated_fields
---
django/contrib/admin/media/js/prepopulate.js | 14 +++++++-------
django/contrib/admin/media/js/prepopulate.min.js | 2 +-
.../admin/templates/admin/edit_inline/stacked.html | 5 ++++-
.../admin/templates/admin/edit_inline/tabular.html | 5 ++++-
.../templates/admin/prepopulated_fields_js.html | 2 +-
5 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/django/contrib/admin/media/js/prepopulate.js b/django/contrib/admin/media/js/prepopulate.js
index 09483bb..24f24f9 100644
a
|
b
|
|
4 | 4 | Depends on urlify.js |
5 | 5 | Populates a selected field with the values of the dependent fields, |
6 | 6 | URLifies and shortens the string. |
7 | | dependencies - selected jQuery object of dependent fields |
| 7 | dependencies - array of dependent fields id's |
8 | 8 | maxLength - maximum length of the URLify'd string |
9 | 9 | */ |
10 | 10 | return this.each(function() { |
… |
… |
|
20 | 20 | if (field.data('_changed') == true) return; |
21 | 21 | |
22 | 22 | var values = []; |
23 | | dependencies.each(function() { |
24 | | if ($(this).val().length > 0) { |
25 | | values.push($(this).val()); |
26 | | } |
27 | | }); |
| 23 | $.each(dependencies, function(i, field) { |
| 24 | if ($(field).val().length > 0) { |
| 25 | values.push($(field).val()); |
| 26 | } |
| 27 | }) |
28 | 28 | field.val(URLify(values.join(' '), maxLength)); |
29 | 29 | }; |
30 | 30 | |
31 | | dependencies.keyup(populate).change(populate).focus(populate); |
| 31 | $(dependencies.join(',')).keyup(populate).change(populate).focus(populate); |
32 | 32 | }); |
33 | 33 | }; |
34 | 34 | })(django.jQuery); |
diff --git a/django/contrib/admin/media/js/prepopulate.min.js b/django/contrib/admin/media/js/prepopulate.min.js
index f1ca297..98fdc93 100644
a
|
b
|
|
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); |
| 1 | (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); |
| 2 | 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 1ecb790..f1e338f 100644
a
|
b
|
|
53 | 53 | var field = $(this); |
54 | 54 | var input = field.find('input, select, textarea'); |
55 | 55 | var dependency_list = input.data('dependency_list') || []; |
56 | | var dependencies = row.find(dependency_list.join(',')).find('input, select, textarea'); |
| 56 | var dependencies = []; |
| 57 | $.each(dependency_list, function(i, field_name) { |
| 58 | dependencies.push('#' + row.find(field_name).find('input, select, textarea').attr('id')); |
| 59 | }); |
57 | 60 | if (dependencies.length) { |
58 | 61 | input.prepopulate(dependencies, input.attr('maxlength')); |
59 | 62 | } |
diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html
index 35dea39..a5b1a89 100644
a
|
b
|
|
99 | 99 | var field = $(this); |
100 | 100 | var input = field.find('input, select, textarea'); |
101 | 101 | var dependency_list = input.data('dependency_list') || []; |
102 | | var dependencies = row.find(dependency_list.join(',')).find('input, select, textarea'); |
| 102 | var dependencies = []; |
| 103 | $.each(dependency_list, function(i, field_name) { |
| 104 | dependencies.push('#' + row.find(field_name).find('input, select, textarea').attr('id')); |
| 105 | }); |
103 | 106 | if (dependencies.length) { |
104 | 107 | input.prepopulate(dependencies, input.attr('maxlength')); |
105 | 108 | } |
diff --git a/django/contrib/admin/templates/admin/prepopulated_fields_js.html b/django/contrib/admin/templates/admin/prepopulated_fields_js.html
index 4aa6380..43ef5ba 100644
a
|
b
|
|
17 | 17 | |
18 | 18 | $('.empty-form .{{ field.field.name }}').addClass('prepopulated_field'); |
19 | 19 | $(field.id).data('dependency_list', field['dependency_list']) |
20 | | .prepopulate($(field['dependency_ids'].join(',')), field.maxLength); |
| 20 | .prepopulate(field['dependency_ids'], field.maxLength); |
21 | 21 | {% endfor %} |
22 | 22 | })(django.jQuery); |
23 | 23 | </script> |