Abhishek Bajaj
Abhishek Bajaj

Reputation: 100

Some part of my Django form should change based on TypedChoiceField list selection

I am new to Django. I have a requirement where in based on the TypedChoiceField list selection some part of the form should be changed. Meaning for a particular selection I need some fields to be displayed on the webpage and for other selection I need some other fields to be displayed on the webpage.

If there is already a similar page existing, please point me to that page, it will help me a lot.

Upvotes: 0

Views: 80

Answers (1)

Jake Denison
Jake Denison

Reputation: 84

What I would do is set up a javascript static file (here's a tutorial) that hides and shows elements using the select method.

For example, if you had categories that each needed a different set of fields, you could put all your categories into a <select> element and then using some simple JS, display the desired fields:

$("#select_object").change(function () {
    toggleFields();
});

In that case, #select_object would be that <select> element. Whenever it changes (the user selects something) it shows the fields you want.

Upvotes: 1

Related Questions