Django Form Wizard With Conditional Questions
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
Solution 1:
Try to replace __init__
method of your form with custom clean_are_you_cool
method. So, if user submit value Yes
you should check if how_cool
field is populated too. You also should do this on client side to provide great user experience. Something like this with forms:
def clean_are_you_cool(self):
if self.cleaned_data.get('are_you_cool', None) == 'Yes':
if self.cleaned_data.get('how_cool', None) is not None:
# Actions for cool user.
pass
# Or if user not cool.
Post a Comment for "Django Form Wizard With Conditional Questions"