News for hackers. Stuff that matters.
Re:Eighteen months of Django by scott_w on Wednesday May 08, 2013 @04:23AM (#5673121)
If I'm understanding you correctly, you want to have the fields on the form depend on the contents of what was entered on the previous form e.g. if user selects name, ask for name, otherwise ask for address.

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.

Re:Eighteen months of Django by porker on Wednesday May 08, 2013 @05:04AM (#5673233)
Not quite - that happens sometimes and I use logic in the controller (ugh) to switch the form class.

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!

Re:Eighteen months of Django by scott_w on Wednesday May 08, 2013 @05:42AM (#5673315)
Ah, I see now. For certain cases e.g. repeating the same form over and over, you can use formsets, but that doesn't work when you have two different forms.

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.

Re:Eighteen months of Django by masklinn on Wednesday May 08, 2013 @06:09AM (#5673379)
Note that one thing you can do is build smaller forms and mix them up. There's no issue with mixing up 3 or 4 smaller (django) forms in the same (HTML) form, quite the opposite.
Re:Eighteen months of Django by TomaszZielinski on Monday May 13, 2013 @04:38AM (#5697723)
Re server-side validation that adapts to the incoming data, I think it's easier to write a small mixin that fits your needs than to use a generic library (assuming there's one).