Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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
Andrew Godwin authored October 10, 2010
14  django/contrib/admin/media/js/prepopulate.js
@@ -4,7 +4,7 @@
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,15 +20,15 @@
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);
2  django/contrib/admin/media/js/prepopulate.min.js
... ...
@@ -1 +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);
  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);
5  django/contrib/admin/templates/admin/edit_inline/stacked.html
@@ -53,7 +53,10 @@
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
                 }
5  django/contrib/admin/templates/admin/edit_inline/tabular.html
@@ -99,7 +99,10 @@
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
                 }
2  django/contrib/admin/templates/admin/prepopulated_fields_js.html
@@ -17,7 +17,7 @@
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>

0 notes on commit be190d1

Please sign in to comment.
Something went wrong with that request. Please try again.