Opened 10 years ago

Closed 8 years ago

Last modified 7 years ago

#9983 closed (fixed)

Javascript issue on admin interface with prepopulated_fields

Reported by: Matias Surdi Owned by: Carl Meyer
Component: contrib.admin Version: 1.0
Severity: Keywords:
Cc: kevin@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I've noticed that if you have a ModelAdmin with the prepopulated_fields
attribute set to:

prepopulated_fields = {"object_identifier": ("object_type",)}

where the field "object_type" is a dropdown box (that is, has a
choices=CHOICES argument) then the javascript that autofills the
"object_identifier" field does not work properly when you choose an
element with the mouse (what most users do).

To solve this, I modified

replacing the event "onkeyup" on line 5 for "onchange".

I think this change should be applied to trunk.

Attachments (2)

populatedfields_9983.diff (1.7 KB) - added by Kevin Kubasik 9 years ago.
populatedfields_9983_2.diff (1.7 KB) - added by Kevin Kubasik 9 years ago.

Download all attachments as: .zip

Change History (16)

comment:1 Changed 10 years ago by Carl Meyer

If I'm not mistaken, the side effect of using onchange would be that prepopulated fields based on text inputs won't update until the user exits the text input, rather than updating on every keystroke. That seems like a regression to me. Would it be possible to support both cases by hooking into both onkeyup and onchange?

comment:2 Changed 10 years ago by Jacob

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:3 Changed 10 years ago by Russell Keith-Magee

Component: Uncategorizeddjango.contrib.admin

comment:4 Changed 9 years ago by Kevin Kubasik

Owner: changed from nobody to Kevin Kubasik

Fixing it.

Changed 9 years ago by Kevin Kubasik

Attachment: populatedfields_9983.diff added

comment:5 Changed 9 years ago by Kevin Kubasik

Ok, I have a patch for a bit of a dual-fix.

1) Listens to both events so that mouse or keyboard will get the autopopulation of the field.
2) Handle the 'choice' instance by using the name and not the value of the select box.

Let me know if it looks good.

comment:6 Changed 9 years ago by Kevin Kubasik

Has patch: set

Changed 9 years ago by Kevin Kubasik

Attachment: populatedfields_9983_2.diff added

comment:7 Changed 9 years ago by Kevin Kubasik

Cc: kevin@… added

comment:8 Changed 9 years ago by anonymous

The following is also another similar patch for this issue:

comment:9 Changed 9 years ago by Jacob

milestone: 1.11.2

Pushing to 1.2: UI annoyance.

comment:10 Changed 9 years ago by James Bennett

milestone: 1.21.3

I'm going to bump this off the 1.2 milestone, for a couple reasons:

  1. There are several tickets (this one, #9110, #9264 and #9784) all exposing cases where the event handling for prepopulated_fields falls over in specific edge cases, so the real solution is not to fix any of these individually but rather to make prepopulate_from more robust.
  2. I suspect the admin-ui work will be coming up for discussion in the 1.3 timeframe, and that's a more solid place to talk about dealing with this.

comment:11 Changed 9 years ago by Carl Meyer

Owner: changed from Kevin Kubasik to Carl Meyer
Status: newassigned

Closed #9110 as dupe of this; the patch here seems to have gotten more attention.

comment:12 Changed 9 years ago by Sean Brant

#13068 has a patch that fixes this issue as well.

comment:13 Changed 8 years ago by Luke Plant

Resolution: fixed
Status: assignedclosed

(In [12937]) Fixed #13068, #9264, #9983, #9784 - regression with pre-populated fields and javascript inlines, and related bugs.

Thanks to hejsan for the report, and to Sean Brant and Carl Meyer for the patch.

#13068 is a regression caused by the new javascript inline forms in the
admin. The others were existing javascript bugs with prepopulated fields.
Since the solution depends on jQuery and would likely be very hard to
backport without it, it will not be backported to 1.1.X.

comment:12 Changed 7 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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