Opened 7 years ago

Closed 7 years ago

#10131 closed (duplicate)

When using an m2m with raw_id_fields, "add another" pop-up replaces field value instead of appending to list

Reported by: onemoreryan@… Owned by: nobody
Component: contrib.admin Version: 1.0
Severity: Keywords: m2m, raw_id_fields, javascript
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When adding m2m relationships to a record via raw_id_field, selecting an existing object from the database works as expected - appending the new ID to a comma-separated list inside the INPUT element. However, when using the admin pop-up's "Add another" function, the m2m field value is not appended to, but overwritten.

Example use: A PhotoSet model has an m2m to a Photo model, using raw_id_field. When creating a PhotoSet, the user should be able to create and upload new Photo records on the fly via the raw_id_field's pop-up form. The ID for each Photo thus created should append to the list in PhotoSet, but instead each new ID just overwrites the old value.

I believe the problem is in /contrib/admin/js/admin/RelatedObjectLookups.js. The dismissRelatedLookupPopup function (called when user selects an existing record) checks for vManyToManyRawIdAdminField, and appends if there's already a value there. But the dismissAddAnotherPopup function simply replaces the value of the INPUT element. Locally, this problem seems to be fixed by wrapping that same vManyToManyRawIdAdminField check inside the dismissAddAnotherPopup IF statement for (elem.nodeName == 'INPUT').

Attachments (1)

RelatedObjectLookups.js.diff (647 bytes) - added by onemoreryan@… 7 years ago.
addition of append to dismissAddAnotherPopup in case of vManyToManyRawIdAdminField

Download all attachments as: .zip

Change History (2)

Changed 7 years ago by onemoreryan@…

addition of append to dismissAddAnotherPopup in case of vManyToManyRawIdAdminField

comment:1 Changed 7 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

#9341 is the same, I believe; I added a note over there that there's a patch on this one.

Note: See TracTickets for help on using tickets.
Back to Top