Opened 6 years ago

Closed 5 years ago

Last modified 3 years ago

#9983 closed (fixed)

Javascript issue on admin interface with prepopulated_fields

Reported by: msurdi Owned by: carljm
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: UI/UX:

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 kkubasik 6 years ago.
populatedfields_9983_2.diff (1.7 KB) - added by kkubasik 6 years ago.

Download all attachments as: .zip

Change History (16)

comment:1 Changed 6 years ago by carljm

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 6 years ago by jacob

  • milestone set to 1.1
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 6 years ago by russellm

  • Component changed from Uncategorized to django.contrib.admin

comment:4 Changed 6 years ago by kkubasik

  • Owner changed from nobody to kkubasik

Fixing it.

Changed 6 years ago by kkubasik

comment:5 Changed 6 years ago by kkubasik

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 6 years ago by kkubasik

  • Has patch set

Changed 6 years ago by kkubasik

comment:7 Changed 6 years ago by kkubasik

  • Cc kevin@… added

comment:8 Changed 6 years ago by anonymous

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

comment:9 Changed 6 years ago by jacob

  • milestone changed from 1.1 to 1.2

Pushing to 1.2: UI annoyance.

comment:10 Changed 5 years ago by ubernostrum

  • milestone changed from 1.2 to 1.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 5 years ago by carljm

  • Owner changed from kkubasik to carljm
  • Status changed from new to assigned

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

comment:12 Changed 5 years ago by seanbrant

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

comment:13 Changed 5 years ago by lukeplant

  • Resolution set to fixed
  • Status changed from assigned to closed

(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 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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