Multi-step forms can be implemented in Django using Form wizards [1]. In order to optionally show fields or make them required I think you could build it easily using the WizardView.get_form method [2]. The functionality to skip steps is built-in and it's very easy implement using conditional views [3].
In conclusion, it's fairly easy to implement the functionality you described using only the core framework without the need to rely on external packages.
[1] - https://docs.djangoproject.com/en/dev/ref/contrib/formtools/... [2] - https://docs.djangoproject.com/en/dev/ref/contrib/formtools/... [3] - https://docs.djangoproject.com/en/dev/ref/contrib/formtools/...
Have you seen anything saying it helps to build adaptive forms like [1]?
However, the way I would go about building something like that is by using the form wizard (mentioned in my previous comment) with a combination of forms/modelforms [1] and formsets [2]. Formsets are used in situations when you need to display the same form multiple times on the same page (like the multiple addresses/benefits income in your example). However, you would have to implement all the client side interaction yourself since Django does not provide this by default (there are some libraries which are supposed to help with this but I haven't tried them myself [3]).
One thing worth mentioning is that by default, the form wizard only allows you to display either a Form, or a Formset in a step/page. However, there is a ticket open for this [4] which links to a helper class: form_container.py [5] which helps overcome this problem. Hopefully, this will be included in future versions of Django.
Hope this helps.
[1] - https://docs.djangoproject.com/en/dev/topics/forms/modelform... [2] - https://docs.djangoproject.com/en/dev/topics/forms/formsets/ [3] - https://code.google.com/p/django-dynamic-formset/ [4] - https://code.djangoproject.com/ticket/18830 [5] - https://code.djangoproject.com/attachment/ticket/18830/form_...
It would be great if there was a ready-made add-on combining all these areas but I don't know any personally. I also suspect think that writing such a generic helper might not be a great idea as everyone needs something a bit different, so using the mentioned lower level components and combining them on your own could be the best way to go here.
In that case, I tend to use class-based views and set different forms, templates etc. depending on those values. If the form is different enough, it's easier just to send them to a completely different URL.
This is what I mean: an adaptive form http://screencast.com/t/SutggDU5
The server-side validation has to adapt depending on the data coming from the client-side, and varies a lot.
Perhaps others don't build forms like this much and so web frameworks don't deal with them; I get one like this every few months!
I still think a solution is to use multiple forms and form types rather than one big form. Perhaps you can prefix the field names on the template and use that to determine which form they go to inside the view. It makes your logic a little simpler in any case.
Would love to know the best way people handle this.
I've just implemented one of these in PHP using the 'old' Symfony 1.4 and it was painful. I ended up hardcoding most of the frontend, and writing ridiculous modifications for "add another row" and validation.
Is Django any better at that? Complex forms have been my pain point for over 11 years, and if a framework handles them... I'm in!