Opened 17 years ago
Closed 13 years ago
#6388 closed Bug (wontfix)
as_p produce invalid HTML for RadioSelect
Reported by: | Batiste Bieler | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | simonluijk@…, m@… | Triage Stage: | Design decision needed |
Has patch: | no | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
An ul element must not exist in a p element. This produce some CSS problem because rules like this will not be applied by Mozilla/Konqueror : p ul {color:red}
http://code.djangoproject.com/browser/django/trunk/tests/regressiontests/forms/regressions.py#L43
Change History (12)
comment:1 by , 17 years ago
Component: | Uncategorized → django.newforms |
---|
comment:2 by , 17 years ago
Summary: | as_p produce invalid HTML for ChoiceField → as_p produce invalid HTML for RadioSelect |
---|
comment:3 by , 17 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 15 years ago
Needs tests: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:5 by , 15 years ago
comment:6 by , 15 years ago
Owner: | changed from | to
---|---|
Status: | assigned → new |
comment:7 by , 14 years ago
Cc: | added |
---|---|
Triage Stage: | Accepted → Design decision needed |
A decision needs to be made in regards to backwards compatibility. So moving to DDN.
I am new to this so if this is wrong please slap me gently!
comment:8 by , 14 years ago
Cc: | added |
---|
comment:9 by , 14 years ago
#14776 reported this again.
Fortunately, there exists a RadioFieldRenderer
helper class for the RadioSelect
widget that is in charge of its rendering as a whole and can choose a (variation of) RadioInput
for rendering each radio select <INPUT>
. RadioSelect()
accepts a 'renderer'
argument. The key method is .render()
. E.g.:
from django.forms import RadioFieldRenderer, RadioSelect class MyRFRenderer(RadioFieldRenderer): def render(): return mark_safe(u'<div id=blah>\n%s</div>\n' % u'\n'.join([u'%s'% force_unicode(w) for w in self]) + u'\n') ... class MyModelForm(ModelForm): some_field = forms.ModelChoiceField(queryset=..., renderer=MyRFRenderer) Meta: model = MyModel
So fixing this (and possibly #13401, although it is a bit more convoluted) is already possible for developers.
If we are going to fix in Django the problem is the mechanism of backward compatibility and/or gradual deprecation+ warning to use.
comment:10 by , 14 years ago
I like this approach to form rendering:
https://github.com/brutasse/django-floppyforms
Django could have some templates called form_as_p.html and form_as_table.html that people could override?
comment:12 by , 13 years ago
Easy pickings: | unset |
---|---|
Resolution: | → wontfix |
Status: | new → closed |
UI/UX: | unset |
This is a minor bug and there's no reasonable backwards-compatible way around it. As_p is going to continue to render with paragraph tags, and UL is the logical default markup for a radio select. The fix is to not use as_p if you have a radio select field, or to customize your radio field renderer as documented above (and hopefully soon we'll have an even better way with #15667). Methods like as_p are just for quick prototyping - if you care about your markup, render your form in your own templates.
The difficulty here is that as_p() wraps the <p></p> around, so the only proper option I see is to stop using <ul> in radioboxes.
However, this would break backwards compatibility, e.g. people styling these lists with CSS.