Opened 17 years ago
Closed 17 years ago
#6307 closed (duplicate)
Creating new related object through popup interface in admin can produce JavaScript error
Reported by: | Webchemist | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | newforms-admin |
Severity: | Keywords: | popup | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I got an JavaScript error when trying to create an related object through popup window in django admin
Django version: 0.97-newforms-admin-SVN-6991
Error: text.replace is not a function
Source: http://127.0.0.1:8000/admin-media/js/admin/RelatedObjectLookups.js
Line: 6
This error is produced in this function:
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); if (elem) { if (elem.nodeName == 'SELECT') { var o = new Option(newRepr, newId); elem.options[elem.options.length] = o; o.selected = true; } else if (elem.nodeName == 'INPUT') { elem.value = newId; } } else { var toId = name + "_to"; elem = document.getElementById(toId); var o = new Option(newRepr, newId); SelectBox.add_to_cache(toId, o); SelectBox.redisplay(toId); } win.close(); }
It is need to change the lines (call toString() method for every entering value, because here a string expected):
.... newId = html_unescape(newId.toString()); newRepr = html_unescape(newRepr.toString()); ....
Attachments (1)
Change History (6)
comment:1 by , 17 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 17 years ago
comment:2 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
I ran into this as well and solved it a bit differently. I think it's cleaner and more in line with the comments surrounding the affected code if all primary keys get passed as strings. See attached patch.
comment:3 by , 17 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:4 by , 17 years ago
I can confirm that this bug affects 0.97-newforms-admin-SVN-7192 and that the patch from Jonas fixes it.
comment:5 by , 17 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Patch for django/contrib/admin/options.py