Opened 7 years ago

Closed 7 years ago

#29011 closed Cleanup/optimization (wontfix)

forms.Field with space in dynamically generated forms.Form leads to wrong assigned id in generated HTML form

Reported by: pdehaye Owned by: nobody
Component: Forms Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by pdehaye)

If you do:

import django
from django.forms import Form
from django.forms import CharField
PersonForm = type('Person', (Form,), {"work address":CharField(max_length=128)})
person = PersonForm()
person.as_ul()

You get

'<li><label for="id_work address">Work address:</label> <input type="text" name="work address" maxlength="128" required id="id_work address" /></li>'

I think the id="id_work address" is suboptimal here. Maybe everything should be underscored? At least the doc, which references id_<field-name>, should be improved (also present in 2.0 doc)

Change History (2)

comment:1 by pdehaye, 7 years ago

Description: modified (diff)

comment:2 by Tim Graham, 7 years ago

Resolution: wontfix
Status: newclosed
Type: UncategorizedCleanup/optimization

I don't see a strong argument for making a change here. If you're generating field names that aren't valid when using a normal declarative form, you're on your own. I don't think this is a normal use case that needs documentation.

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