Code

Ticket #19082: better_prepopulated_fields_logic.diff

File better_prepopulated_fields_logic.diff, 1.6 KB (added by msaelices, 19 months ago)

Better autocompletion logic

Line 
1diff --git a/django/contrib/admin/static/admin/js/prepopulate.js b/django/contrib/admin/static/admin/js/prepopulate.js
2index 24f24f9..27a1498 100644
3--- a/django/contrib/admin/static/admin/js/prepopulate.js
4+++ b/django/contrib/admin/static/admin/js/prepopulate.js
5@@ -14,10 +14,15 @@
6             field.change(function() {
7                 field.data('_changed', true);
8             });
9+            if (field.val()) {
10+                field.data('_filled', true);
11+            } else {
12+                field.data('_filled', false);
13+            }
14 
15             var populate = function () {
16                 // Bail if the fields value has changed
17-                if (field.data('_changed') == true) return;
18+                if (field.data('_changed') == true || field.data('_filled') == true) return;
19 
20                 var values = [];
21                 $.each(dependencies, function(i, field) {
22diff --git a/django/contrib/admin/templatetags/admin_modify.py b/django/contrib/admin/templatetags/admin_modify.py
23index f6ac596..65ca7af 100644
24--- a/django/contrib/admin/templatetags/admin_modify.py
25+++ b/django/contrib/admin/templatetags/admin_modify.py
26@@ -9,7 +9,7 @@ def prepopulated_fields_js(context):
27     the prepopulated fields for both the admin form and inlines.
28     """
29     prepopulated_fields = []
30-    if context['add'] and 'adminform' in context:
31+    if 'adminform' in context:
32         prepopulated_fields.extend(context['adminform'].prepopulated_fields)
33     if 'inline_admin_formsets' in context:
34         for inline_admin_formset in context['inline_admin_formsets']: