HI
I want to align the radio buttons horizontally. By default django forms displays in vertical format.
feature_type = forms.TypedChoiceField(choices = formfields.FeatureType, widget = forms.RadioSelect)
Is there any special parameter that we can pass for radio buttons alignment?
Thanks in advance
To make a horizontal radio button set, add the data-type="horizontal" to the fieldset . The framework will float the labels so they sit side-by-side on a line, hide the radio button icons and only round the left and right edges of the group.
Yes, there is a way. Drag a radio list widget to your screen, go to the Properties tab and select 'Orientation' -> Horizontal.
Thats the behavior of the RadioField
. If you want it rendered horizontally, create a horizontal renderer, like something as follows:
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),
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With