Opened 16 years ago

Closed 16 years ago

Last modified 12 years ago

#7903 closed (fixed)

Javascript errors with prepopulated_fields in admin

Reported by: ElliottM Owned by: Jacob
Component: contrib.admin Version: dev
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: no UI/UX: no

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 16 years ago.
7903.diff (1.1 KB ) - added by Alex Gaynor 16 years ago.

Download all attachments as: .zip

Change History (17)

comment:1 by ElliottM, 16 years ago

Summary: Javascript errors with preopulated_fieldsJavascript errors with preopulated_fields in admin

comment:2 by ElliottM, 16 years ago

Keywords: admin javascript prepopulated fields prepopulated_fields added

comment:3 by Brian Rosner, 16 years ago

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 by Brian Rosner, 16 years ago

Correction, not working right with the textarea element ;)

comment:5 by ElliottM, 16 years ago

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.

by Matthias Kestenholz, 16 years ago

Attachment: 7903.patch added

comment:6 by Matthias Kestenholz, 16 years ago

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

comment:7 by Matthias Kestenholz, 16 years ago

Has patch: set

comment:8 by Eric Holscher, 16 years ago

milestone: 1.0
Triage Stage: UnreviewedDesign decision needed

comment:9 by Charlie La Mothe, 16 years ago

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

comment:10 by Jacob, 16 years ago

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

comment:11 by Malcolm Tredinnick, 16 years ago

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")?

by Alex Gaynor, 16 years ago

Attachment: 7903.diff added

comment:12 by Alex Gaynor, 16 years ago

Triage Stage: AcceptedReady for checkin

comment:13 by Alex Gaynor, 16 years ago

Patch needs improvement: unset

comment:14 by Malcolm Tredinnick, 16 years ago

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

milestone: 1.0

Milestone 1.0 deleted

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