Opened 15 years ago

Closed 12 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


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}

Change History (12)

comment:1 Changed 15 years ago by anonymous

Component: Uncategorizeddjango.newforms

comment:2 Changed 15 years ago by Matt McClanahan

Summary: as_p produce invalid HTML for ChoiceFieldas_p produce invalid HTML for RadioSelect

comment:3 Changed 15 years ago by Jacob

Triage Stage: UnreviewedAccepted

comment:4 Changed 13 years ago by Sasha Romijn

Needs tests: set
Owner: changed from nobody to Sasha Romijn
Status: newassigned

comment:5 Changed 13 years ago by Sasha Romijn

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.

comment:6 Changed 13 years ago by Sasha Romijn

Owner: changed from Sasha Romijn to nobody
Status: assignednew

comment:7 Changed 13 years ago by simonluijk

Cc: simonluijk@… added
Triage Stage: AcceptedDesign 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 Changed 13 years ago by JMagnusson

Cc: m@… added

comment:9 Changed 13 years ago by Ramiro Morales

#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)
        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 Changed 13 years ago by Batiste Bieler

I like this approach to form rendering:

Django could have some templates called form_as_p.html and form_as_table.html that people could override?

comment:11 Changed 12 years ago by Julien Phalip

Severity: Normal
Type: Bug

Also see #15667.

comment:12 Changed 12 years ago by Carl Meyer

Easy pickings: unset
Resolution: wontfix
Status: newclosed
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.

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