Opened 16 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 anonymous, 16 years ago

Component: Uncategorizeddjango.newforms

comment:2 by Matt McClanahan, 16 years ago

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

comment:3 by Jacob, 16 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Sasha Romijn, 14 years ago

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

comment:5 by Sasha Romijn, 14 years ago

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 by Sasha Romijn, 14 years ago

Owner: changed from Sasha Romijn to nobody
Status: assignednew

comment:7 by simonluijk, 13 years ago

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 by JMagnusson, 13 years ago

Cc: m@… added

comment:9 by Ramiro Morales, 13 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 Batiste Bieler, 13 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:11 by Julien Phalip, 13 years ago

Severity: Normal
Type: Bug

Also see #15667.

comment:12 by Carl Meyer, 13 years ago

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