Code

Ticket #1404: trunk-admin_popup_selectfilter_fix.diff

File trunk-admin_popup_selectfilter_fix.diff, 1.2 KB (added by Tom Tobin <korpios@…>, 8 years ago)

patch against r2408 of trunk to fix admin popup breakage with m2m fields and filter_interface

Line 
1Index: contrib/admin/media/js/admin/RelatedObjectLookups.js
2===================================================================
3--- contrib/admin/media/js/admin/RelatedObjectLookups.js        (revision 2408)
4+++ contrib/admin/media/js/admin/RelatedObjectLookups.js        (working copy)
5@@ -29,12 +29,20 @@
6 function dismissAddAnotherPopup(win, newId, newRepr) {
7     var name = win.name.replace(/___/g, '.')
8     var elem = document.getElementById(name);
9-    if (elem.nodeName == 'SELECT') {
10+    if (elem) {
11+        if (elem.nodeName == 'SELECT') {
12+            var o = new Option(newRepr, newId);
13+            elem.options[elem.options.length] = o
14+            elem.selectedIndex = elem.length - 1;
15+        } else if (elem.nodeName == 'INPUT') {
16+            elem.value = newId;
17+        }
18+    } else {
19+        var toId = name + "_to";
20+        elem = document.getElementById(toId);
21         var o = new Option(newRepr, newId);
22-        elem.options[elem.options.length] = o
23-        elem.selectedIndex = elem.length - 1;
24-    } else if (elem.nodeName == 'INPUT') {
25-        elem.value = newId;
26+        SelectBox.add_to_cache(toId, o);
27+        SelectBox.redisplay(toId);
28     }
29     win.close();
30 }