Opened 5 years ago

Closed 5 years ago

#28060 closed New feature (wontfix)

Add the horizontal radio selection renderer

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

Description

I propose to add the render for horizontal radio selection. When a set of choices is rendered into a radio selection list, Django will list the radio selection vertically by default. People come to trouble when they want to make the radio list horizontal.

I propose to add a Horizontal radio selection render that is similar to

from django.utils.safestring import mark_safe

class HorizontalRadioRenderer(forms.RadioSelect.renderer):
  def render(self):
    return mark_safe(u'\n'.join([u'%s\n' % w for w in self]))


class ApprovalForm(forms.Form):
    approval = forms.ChoiceField(choices=APPROVAL_CHOICES,
                 initial=0,
                 widget=forms.RadioSelect(renderer=HorizontalRadioRenderer),
                                 )

This could as solve ticket #28059.

PS. The code for HorizontalRadioRenderer seems to be a folklore on the internet for years, it can be found on *stackoverflow and *UTexas Wiki.

Change History (4)

comment:1 Changed 5 years ago by Musen

Owner: changed from nobody to Musen
Status: newassigned

comment:2 Changed 5 years ago by Musen

Component: UncategorizedForms
Needs documentation: set
Needs tests: set
Type: UncategorizedNew feature
Version: 1.11master

comment:3 Changed 5 years ago by Simon Charette

Isn't this something that can be achieved by styling the list elements to be displayed horizontally instead?

Just wanted to say I don't think that stripping all the markup is the way to go here.

comment:4 Changed 5 years ago by Tim Graham

Resolution: wontfix
Status: assignedclosed

I think #28059 will be fixed by restoring the CSS classes on the <ul> that were there before 1.11. Presumably the same solution could be used in other apps. The code in the ticket description no longer words after the introduction of template-based widget rendering in Django 1.11.

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