In my Django application, I currently have a form wizard with a few form classes. I would like to have the ability to have conditional questions. Meaning if the user selects yes for a certain question, another question within the form will become required and javascript will make the question visible. I found an example of how to do this online, however it doesn't work. Any suggestions on how I can create this functionality?
class QuestionForm(forms.Form):
COOL_LIST = (
('cool','Cool'),
('really cool','Really Cool'),
)
YES, NO = 'yes','no'
YES_NO = (
(YES,'Yes'),
(NO,'No'),
)
are_you_cool = forms.ChoiceField(choices=YES_NO,label='Are you cool?')
how_cool = forms.MultipleChoiceField(required=False,widget=CheckboxSelectMultiple, choices=COOL_LIST,label='How cool are you?')
def __init__(self, data=None, *args, **kwargs):
super(QuestionForm, self).__init__(data, *args, **kwargs)
if data and data.get('are_you_cool', None) == self.YES:
self.fields['how_cool'].required = True