I am using django-allauth and created a custom signup form that inherits from SignupForm. How do I remove the default placeholder from the email field? I don't want a placeholder.
from allauth.account.forms import SignupForm
class UserSignUpForm(SignupForm):
first_name = forms.CharField(max_length=155)
last_name = forms.CharField(max_length=155)
mobile = forms.CharField(max_length=20)
def __init__(self, *args, **kwargs):
super(UserSignUpForm, self).__init__(*args, **kwargs)
del self.fields['password1']
del self.fields['password2']
self.fields['first_name'].widget.attrs.update({
'class': 'required form-control',
})
self.fields['last_name'].widget.attrs.update({
'class': 'required form-control',
})
self.fields['email'].widget.attrs.update({
'class': 'required email form-control',
})
self.fields['mobile'].widget.attrs.update({
'class': 'required form-control',
})
def custom_signup(self, request, user):
user.first_name = self.cleaned_data['first_name']
user.last_name = self.cleaned_data['last_name']
user.mobile_number = self.cleaned_data['mobile']
user.save()
The placeholder
is set in the code as a key in in the widget's attrs
dict.
email = forms.EmailField(widget=forms.TextInput(
attrs={'type': 'email',
'placeholder': _('E-mail address')}))
So you can simply remove that key in the form's __init__
method.
def __init__(self, *args, **kwargs):
super(UserSignUpForm, self).__init__(*args, **kwargs)
del self.fields['email'].widget.attrs['placeholder']
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