0

I'm using django forms to make a user registration form and it has two different types of users

I want that when selecting one of the types of user, in the html it shows registration information specific to that type of user

example: if I choose a doctor I will ask for his medical identification, if I choose a patient with a medical history

Like this

form.py

usertype= forms.ChoiceField(  initial='----',choices=USER_TYPE_CHOICES ,widget=forms.Select(attrs={'class': 'form-control'}))

.html

<div class="row">
                  <div class="col-md-3 px-md-1">
                    <div class="form-group">
                      <label>User type</label>
                      {{form.usertype}}
                    </div>
                  </div>
                </div>
Rod
  • 57
  • 5
  • 1
    You need some javascript for that. Your server (django) does not know anything about things happening on the live page. Alternatively, make the form submit when user type is selected and render template based on that information (but you need some JS to make this autosubmission work too). – STerliakov Jun 20 '22 at 21:03
  • If you're not wanting to learn JavaScript yet, you could also just put two buttons on the screen, one for doctor and one for patient. Depending on which one they click sends them to a page with the correct form – Adam James Jun 20 '22 at 21:19
  • @SUTerliakov is correct. The only way to efficiently address the requirement in the OP in a usable way is to use javascript. Also, you'll have to break up `(( form.usertype }}` into individual fields. Having looked at this, any workaround without javascript will lead to a poor user experience quickly. Might I suggest you include `models.py` so we can see the fields you are working with? – Carewen Jun 21 '22 at 02:08

0 Answers0