setting help_text for each choice in a RadioSelect

后端 未结 2 1237
孤城傲影
孤城傲影 2021-02-08 19:26

I can set the help_text attribute on any form field, but is it possible to set help_text on the choices used for a RadioSelect()?

I\'d looking for a clean way to show so

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-08 20:07

    Assuming you're using RadioSelect as a widget for forms.ChoiceField, you can do something like:

    choices = (('1', 'First help_text here'),
               ('2', 'Second help_text here'),
               ('3', 'Third help_text here'),
              )
    
    class MyForm(forms.Form):
        ...
        choice = forms.ChoiceField(widget = RadioSelect, choices = choices)
    

    This isn't a strict use of help_text but it should get the job done in most cases.

提交回复
热议问题