My question is regarding form subclassing in Django. How would I modify some attribute, while retaining the other attributes, of an inherited field?
For example, I have a form, called SignUpForm, which subclasses from UserCreationForm.
UserCreationForm:
...
password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
...
In SignUpForm, I would like to override widget with widget=TextInput(attrs={'size': 30}) while keeping label the same. Is this possible? If so, how? Thanks.
You can do it in __init__
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.fields['password1'].widget = TextInput(attrs={'size': 30})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With