Opened 17 years ago

Last modified 17 years ago

#4174 closed

[newforms-admin] prepopulated_fields results in javascript error (None is not defined) — at Version 10

Reported by: forest@… Owned by: Adrian Holovaty
Component: contrib.admin Version: newforms-admin
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Adrian Holovaty)

I get this in Firefox 2:

Error: None is not defined
Source File: http://localhost:8080/admin/page/section/add/
Line: 142

The javascript source is as follows:

<script type="text/javascript">

    document.getElementById("id_slug").onchange = function() { this._changed = true; };
    
    document.getElementById("id_title").onkeyup = function() {
        var e = document.getElementById("id_slug");
        if (!e._changed) { e.value = URLify(document.getElementById("id_title").value, None); }
    }
    

</script>

-Forest

Change History (11)

comment:1 by Simon G. <dev@…>, 17 years ago

Triage Stage: UnreviewedAccepted
Version: other branchnewforms branch

comment:2 by Simon G. <dev@…>, 17 years ago

Summary: prepopulated_fields results in javascript error (newforms-admin)[newforms-admin] prepopulated_fields results in javascript error (None is not defined)

comment:3 by Adrian Holovaty, 17 years ago

Version: newforms branchnewforms-admin

comment:4 by Brian Rosner <brosner@…>, 17 years ago

I came across this problem as well. I spent a little bit of time looking through the source to find the root of this problem.

In django/contrib/admin/templates/admin/change_form.html the line that causes the problem is (line 87 as of r5499):

if (!e._changed) { e.value = URLify({% for innerdep in field.dependencies %}document.getElementById("{{ innerdep.auto_id }}").value{% if not forloop.last %} + ' ' + {% endif %}{% endfor %}, {{ field.field.field.max_length }}); }

The call to {{ field.field.field.max_length }} results in None. This is due to maxlength from the model not being push through to the formfield created by the model Field class. This may also be be field independent, but since pre_populated uses CharFields, it would be more specific to that.

I guess the real question is, should maxlength be pushed over to the form field? I would it should, but perhaps some people will confuse that with an enforcement of that number in the actual form field. I don't know. ;) If it is as simple to move it over, I'd be up for writing a patch to fix that.

comment:5 by Brian Rosner <brosner@…>, 17 years ago

I stand corrected. My comments above should really be disregraded. I looked at this a little more in depth and it turns out this is a problem with the SlugField field implmentation. It subclasses Field and doesn't have a formfield method which Field's formfield method does not push over maxlength. If you subclass SlugField with CharField the problem is solved.

by Brian Rosner <brosner@…>, 17 years ago

patch to fix #4174

comment:6 by anonymous, 17 years ago

Works fine for me, thanks for the patch.

comment:7 by Brian Rosner <brosner@…>, 17 years ago

I believe this has been fixed as of r5926 in newforms-admin. Russell can you comment on this? If so, this ticket can be closed.

comment:8 by Brian Rosner <brosner@…>, 17 years ago

Err, ignore my comment above, this is the wrong ticket ;)

comment:9 by nirvdrum, 17 years ago

I can also verify that the patch does work.

comment:10 by Adrian Holovaty, 17 years ago

Description: modified (diff)

Fixed formatting in description.

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