I have several different profiles I want people to be able to create (let's call them special types of Apples). I am rendering the base Apple form, which contains a drop-down for the type of Apple, Red Apple or Green Apple. Based on this drop-down, I'd like to also display the RedAppleProfileForm, or the GreenAppleProfileForm, ModelForms based off the profiles.
How do I conditionally render these forms?
- I have tried rendering both of them with
display: none
, and changing the display based on selected element value, but because the fields of the rendered forms are mandatory, I can't ever submit, even if the form hasdisplay: none
. If there is a way around this, this is a solution.
Relevant Stack: How to render django form differently based on what user selects?
Notes on this stack: The solution with 4 upvotes seems to work for 2 profiles, such as Red and Green apples, but in my scenario I happen to have 5 different types of Apples, and I don't know how I'd make it work then. The accepted solution could work maybe but I don't fully grasp how? Would I just a BaseForm inherit all 5 of my ProfileForms?
Python3.8, Django 3.0