Customize radioselect default renderer
Asked Answered
T

1

5

I have the following form with radioselect options :

jobStatus = forms.ChoiceField( widget=forms.RadioSelect())

However, it renders the radio buttons in <ul> <li> .. </li></ul> tags.

Could you suggest me any way to render the only radiobutton input ?

Thanks

Trueman answered 25/5, 2011 at 19:54 Comment(0)
F
8

This is a nice how-to for overriding the renderer of the radio select widget.

https://wikis.utexas.edu/display/~bm6432/Django-Modifying+RadioSelect+Widget+to+have+horizontal+buttons

Basically, create a class that inherits from the forms.RadioFieldRenderer class and override the render method. Then in your form when setting the widget use the renderer argument to set the renderer to your custom renderer class.

That being said, I usually just change the appearance using CSS

Falla answered 26/5, 2011 at 1:44 Comment(2)
Works perfect thanks! Is there any general convention where this kind of custom renderers should be in project tree ?Trueman
I think it would depend on if you plan to reuse the renderer in other forms. If not I would put it in the same forms.py file as the form, otherwise with the rest of your "util" or "misc" snippets and import it from there.Falla

© 2022 - 2024 — McMap. All rights reserved.