neversaint neversaint - 4 months ago 14
HTML Question

How to add initial default value in Django's EmailField()

I have the following django scheme:

forms.py

from django import forms

class ContactForm(forms.Form):
name_param = forms.CharField()
email_param = forms.EmailField()
message_param = forms.CharField(widget=forms.Textarea)
recaptcha_param = ReCaptchaField()


My question is:

enter image description here

I'd like to implement something like this.
Also we'd like to enable direct overwrite-as-we-type on the default value.

Oli Oli
Answer

You can add a placeholder attribute to your email_param field. So your forms.py would be:

from django import forms

class ContactForm(forms.Form):
    name_param        = forms.CharField()
    email_param       = forms.EmailField(widget=forms.EmailInput({'placeholder': 'test@example.com'}))
    message_param     = forms.CharField(widget=forms.Textarea)
    recaptcha_param   = ReCaptchaField()