Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove fields from parent form?

I have a form that I use to register users. I have another form that I use to login users. These two forms share common properties such as the username and password.

I tried to create a LoginForm that inherits from RegisterForm but I don't know how to remove fields I don't need for login, such as repeat password or the agree to T&Cs checkbox.

How can I do this? These forms inherit from Form not ModelForm.

like image 245
ruipacheco Avatar asked Oct 23 '25 04:10

ruipacheco


2 Answers

del form.some_field - either after instantiating the form class or in __init__ (after the super call, and you'd use self instead of form).

https://wtforms.readthedocs.io/en/3.0.x/specific_problems/#removing-fields-per-instance

like image 53
ThiefMaster Avatar answered Oct 25 '25 23:10

ThiefMaster


If LoginForm is truly a subset of RegisterForm, you're probably better off reversing your inheritance.

class LoginForm(Form):
    username = ...
    password = ...

class ReigsterForm(LoginForm):
    confirm_password = ...
like image 34
dirn Avatar answered Oct 25 '25 21:10

dirn