Is it possible to map a field to a custom template radio button group?

47 views Asked by At

Question in the title.

I have a form like so

class SelectTypeForm(forms.Form):

the_type = forms.CharField(max_length=100)

I have a custom template with a radio button group. How can make the field get the selected value?

1

There are 1 answers

0
Tarquinius On

Go away from your CharField. Hopefully I understand you correctly and you want to have a radio-button-group with multiple options. Each option represents a string. If the user decides to click the second presented radio-button, the string 'is_stored' gets stored.

class SelectTypeForm(forms.Form):
    choose_type = forms.ChoiceField(label='your type field', choices=(
        ('type_a', 'This string'),
        ('type_b', 'is stored'),
        ('type_c', 'if selected')
    ), widget=forms.RadioSelect, initial='type_b')

If this is not what you meant, please provide your 'custom template with a radio button group'.