i’m using a form with a TypeChoiceField, this is the form’s code:
class AnagraficaForm(forms.Form):
usertype = ((1,'Privato'),(0,'Libero professionista/Azienda'))
nome = forms.CharField(max_length=100)
cognome = forms.CharField(max_length=100)
telefono = forms.CharField(max_length=50,required=False)
email= forms.EmailField(max_length=100,required=False)
indirizzo = forms.CharField(max_length=100)
cap = ITZipCodeField(required=False)
citta = forms.CharField(max_length=100)
codfisc = ITSocialSecurityNumberField(required=False)
piva = ITVatNumberField(required=False)
ragsociale = forms.CharField(max_length=100)
is_privato = forms.TypedChoiceField(
initial=1,
coerce=lambda x: bool(int(x)),
choices=usertype,
#using custom renderer to display radio buttons on the same line
widget=forms.RadioSelect(renderer=HorizRadioRenderer)
)
now i’m trying to set a custom id for the two radio buttons displayed but i havent found yet the right way. any idea?
thx – Luke
You need to customize the renderer
HorizRadioRenderer‘srendermethod, as you need to customize it for each set of radio buttons. If it was just a single field, you could have used the attrs argument to customize the id.