Code

Opened 7 years ago

Closed 7 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: UI/UX:

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);

Attachments (0)

Change History (3)

comment:1 Changed 7 years ago by trbs

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

typo's in second patch :(

correction:

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

comment:2 Changed 7 years ago by trbs

duplicate of #6100

comment:3 Changed 7 years ago by Alex

  • Resolution set to duplicate
  • Status changed from new to closed

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.