3 ms·
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.co
by porker 14y ago
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 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!
- scott_w 14y agoAh, 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.
- masklinn 14y agoNote 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.
- TomaszZielinski 13y agoRe 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).