Opened 6 years ago

Last modified 6 years ago

#29011 closed Cleanup/optimization

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

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 (1)

comment:1 by pdehaye, 6 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top