Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 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 mk 6 years ago.
7903.diff (1.1 KB) - added by Alex 6 years ago.

Download all attachments as: .zip

Change History (17)

comment:1 Changed 6 years ago by ElliottM

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Javascript errors with preopulated_fields to Javascript errors with preopulated_fields in admin

comment:2 Changed 6 years ago by ElliottM

  • Keywords admin javascript prepopulated fields prepopulated_fields added

comment:3 Changed 6 years ago by brosner

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

Correction, not working right with the textarea element ;)

comment:5 Changed 6 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 6 years ago by mk

comment:6 Changed 6 years ago by mk

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

  • Has patch set

comment:8 Changed 6 years ago by ericholscher

  • milestone set to 1.0
  • Triage Stage changed from Unreviewed to Design decision needed

comment:9 Changed 6 years ago by clamothe

  • Summary changed from Javascript errors with preopulated_fields in admin to Javascript errors with prepopulated_fields in admin

comment:10 Changed 6 years ago by jacob

  • Owner changed from nobody to jacob
  • Status changed from new to assigned
  • Triage Stage changed from Design decision needed to Ready for checkin

comment:11 Changed 6 years ago by mtredinnick

  • Patch needs improvement set
  • Triage Stage changed from Ready for checkin to Accepted

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

comment:12 Changed 6 years ago by Alex

  • Triage Stage changed from Accepted to Ready for checkin

comment:13 Changed 6 years ago by Alex

  • Patch needs improvement unset

comment:14 Changed 6 years ago by mtredinnick

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

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

comment:15 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.