Opened 17 years ago

Closed 17 years ago

#6284 closed (duplicate)

[newforms-admin] text.replace is not a function

Reported by: trbs Owned by: nobody
Component: contrib.admin Version: newforms-admin
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Saving a new record in the popup of a foreignkey in newform-admin yields a "text.replace is not a function" for me.

This is because in dismissAddAnotherPopup() function in RelatedObjectsLookups.js the newId parameter get html_unescape'd.

But it looks like it correctly gives a Int to the function and not a string hence the replace function fails.

Solution looks as simple as removing the html_unescape function from the function.

Index: RelatedObjectLookups.js
===================================================================
--- RelatedObjectLookups.js	(revision 6979)
+++ RelatedObjectLookups.js	(working copy)
@@ -54,7 +54,6 @@
 function dismissAddAnotherPopup(win, newId, newRepr) {
     // newId and newRepr are expected to have previously been escaped by
     // django.utils.html.escape.
-    newId = html_unescape(newId);
     newRepr = html_unescape(newRepr);
     var name = win.name.replace(/___/g, '.');
     var elem = document.getElementById(name);

But i might be forgetting some other usecase here where a string is passed to the function as 'newId' if so one could use something like:

Index: RelatedObjectLookups.js
===================================================================
--- RelatedObjectLookups.js	(revision 6979)
+++ RelatedObjectLookups.js	(working copy)
@@ -54,7 +54,9 @@
 function dismissAddAnotherPopup(win, newId, newRepr) {
     // newId and newRepr are expected to have previously been escaped by
     // django.utils.html.escape.
-    newId = html_unescape(newId);
+    if (typeof(newIf)!="numer")) {
+	newId = html_unescape(newId);
+    }
     newRepr = html_unescape(newRepr);
     var name = win.name.replace(/___/g, '.');
     var elem = document.getElementById(name);

Change History (3)

comment:1 by trbs, 17 years ago

typo's in second patch :(

correction:

+    if (typeof(newId)!="number") {

comment:2 by trbs, 17 years ago

duplicate of #6100

comment:3 by Alex Gaynor, 17 years ago

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top