Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#7903 closed (fixed)

Javascript errors with prepopulated_fields in admin

Reported by: ElliottM Owned by: Jacob
Component: contrib.admin Version: master
Severity: Keywords: admin javascript prepopulated fields prepopulated_fields
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When I set the prepopulated_fields property in my ModelAdmin, I get the following Javascript error (as reported by firebug):

None is not defined
onkeyup() (line 149)
if (!e._changed) { e.value = URL...ntById("id_description").value, None); }
http://127.0.0.1/admin/network/path/add/

My model:

class Path(models.Model):
	circuit_id=	models.CharField(max_length=16, db_index=True, unique=True)
	
	description=models.CharField(max_length=64)
	comments=	models.TextField(blank=True)
	speed=		models.CharField(max_length=8, blank=True)
	
	in_use=		models.BooleanField(db_index=True)

The ModelAdmin for that model:

class PathAdmin(admin.ModelAdmin):
	list_display=('circuit_id','description','comments','speed','in_use')
	list_filter=('in_use',)
	search_fields=('circuit_id',)
	prepopulated_fields= {'comments':('description',)}

The error results in the comments field not being prepopulated.
This happens both on my Mac 10.5 running Firefox 2.0.0.11 and my Kubuntu Hardy computer running Firefox 3.0

Attachments (2)

7903.patch (1.0 KB) - added by Matthias Kestenholz 8 years ago.
7903.diff (1.1 KB) - added by Alex Gaynor 8 years ago.

Download all attachments as: .zip

Change History (17)

comment:1 Changed 8 years ago by ElliottM

Summary: Javascript errors with preopulated_fieldsJavascript errors with preopulated_fields in admin

comment:2 Changed 8 years ago by ElliottM

Keywords: admin javascript prepopulated fields prepopulated_fields added

comment:3 Changed 8 years ago by Brian Rosner

I am beginning to wonder why you are using a TextField for the field to prepopulate. What is the behavior you want with that? It appears the Javascript is working right the textarea element. I also wonder if this something that should be allowed or not. I tend to lean to preventing the behavior in validation of the ModelAdmin.

comment:4 Changed 8 years ago by Brian Rosner

Correction, not working right with the textarea element ;)

comment:5 Changed 8 years ago by ElliottM

I was just trying it out with a pre-existing model to see how it worked. I didn't even intend to use it like that, just wanted to see it in action.

Changed 8 years ago by Matthias Kestenholz

Attachment: 7903.patch added

comment:6 Changed 8 years ago by Matthias Kestenholz

It probably does not make much sense to support this, but here is a patch which just uses the default SlugField length.

comment:7 Changed 8 years ago by Matthias Kestenholz

Has patch: set

comment:8 Changed 8 years ago by Eric Holscher

milestone: 1.0
Triage Stage: UnreviewedDesign decision needed

comment:9 Changed 8 years ago by Charlie La Mothe

Summary: Javascript errors with preopulated_fields in adminJavascript errors with prepopulated_fields in admin

comment:10 Changed 8 years ago by Jacob

Owner: changed from nobody to Jacob
Status: newassigned
Triage Stage: Design decision neededReady for checkin

comment:11 Changed 8 years ago by Malcolm Tredinnick

Patch needs improvement: set
Triage Stage: Ready for checkinAccepted

This isn't ready for checkin yet, since the patch no longer applies. There's been some refactoring in that template since the patch was created and the relevant code has been moved elsewhere. The idea's good and it can go in, but can somebody regenerate the patch against the new home of that fragment of code (and then bump it back to "ready for checkin")?

Changed 8 years ago by Alex Gaynor

Attachment: 7903.diff added

comment:12 Changed 8 years ago by Alex Gaynor

Triage Stage: AcceptedReady for checkin

comment:13 Changed 8 years ago by Alex Gaynor

Patch needs improvement: unset

comment:14 Changed 8 years ago by Malcolm Tredinnick

Resolution: fixed
Status: assignedclosed

(In [8505]) Fixed #7903 -- Allow admin's prepopulated_from to work with TextFields. Patch
from mk and Alex Gaynor.

comment:15 Changed 5 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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