Forms.py: I want to hide job_role field when user_type= admin selected in ‘is_superuser’ field
class CreateUserForm(HelperForm):
USER_TYPE_CHOICES = (
(False, 'Employee'),
(True, 'Admin'),
)
first_name = forms.CharField(
label="First Name",
max_length=30,
required=True,
validators=[firstNameValidator]
)
last_name = forms.CharField(
label="Last Name",
max_length=30,
required=True,
validators=[lastNameValidator]
)
email = forms.EmailField(
label="Email",
required=True,
validators=[emailValidator]
)
job_role = forms.ModelChoiceField(queryset=Group.objects.all())
is_superuser = forms.ChoiceField(label='User Type', choices=USER_TYPE_CHOICES)
is_active = forms.BooleanField(initial=False, required=False, widget=forms.HiddenInput())
class Meta:
model = User
fields = ('first_name', 'last_name', 'username',
'email', 'is_superuser', 'job_role', 'is_active')