Opened 15 years ago

Closed 14 years ago

Last modified 12 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

Description

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
./django/contrib/admin/templates/admin/prepopulated_fields_js.html

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 15 years ago.
populatedfields_9983_2.diff (1.7 KB ) - added by Kevin Kubasik 15 years ago.

Download all attachments as: .zip

Change History (16)

comment:1 by Carl Meyer, 15 years ago

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 by Jacob, 15 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:3 by Russell Keith-Magee, 15 years ago

Component: Uncategorizeddjango.contrib.admin

comment:4 by Kevin Kubasik, 15 years ago

Owner: changed from nobody to Kevin Kubasik

Fixing it.

by Kevin Kubasik, 15 years ago

Attachment: populatedfields_9983.diff added

comment:5 by Kevin Kubasik, 15 years ago

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 by Kevin Kubasik, 15 years ago

Has patch: set

by Kevin Kubasik, 15 years ago

Attachment: populatedfields_9983_2.diff added

comment:7 by Kevin Kubasik, 15 years ago

Cc: kevin@… added

comment:8 by anonymous, 15 years ago

The following is also another similar patch for this issue:
http://code.djangoproject.com/ticket/9110

comment:9 by Jacob, 15 years ago

milestone: 1.11.2

Pushing to 1.2: UI annoyance.

comment:10 by James Bennett, 14 years ago

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 by Carl Meyer, 14 years ago

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 by Sean Brant, 14 years ago

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

comment:13 by Luke Plant, 14 years ago

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 by Jacob, 12 years ago

milestone: 1.3

Milestone 1.3 deleted

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