I'm using Django 1.6.2 and the new meta options added in 1.6 version on ModelForms as mentioned in this question, the errors on the forms are not displaying like i set them to.
My code:
ModelForm
class UserRegisterForm(forms.ModelForm):
"""A form for creating new users. Includes all the required
fields, plus a repeated password."""
password = forms.CharField(label='Password', widget=forms.PasswordInput)
class Meta:
model = MyUser
fields = ('email','first_name','last_name')
error_messages = {
'email': {
'invalid': u"Hai",
'required': u"Sup",
},
}
def save(self, commit=True):
# Save the provided password in hashed format
user = super(UserRegisterForm, self).save(commit=False)
user.set_password(self.cleaned_data["password"])
if commit:
user.save()
return user
Template
<div class="form-group emailgroup {% if form.email.errors %}has-error has-feedback{% endif %}">
<label for="emailfield">Dirección de correo electrónico</label>
<input type="email" class="form-control" id="emailfield" name="email" required placeholder="¿Cuál es tu dirección de correo electrónico?">
{% if form.email.errors %}<span class="glyphicon glyphicon-remove form-control-feedback"></span>
<span class="help-block">{{ form.email.errors }}</span>
{% endif %}
</div>
Mind the following lines in the template where I print the errors of the field.
{% if form.email.errors %}<span class="glyphicon glyphicon-remove form-control-feedback"></span>
<span class="help-block">{{ form.email.errors }}</span>
{% endif %}
But I still get the predefined error message. What am I doing wrong?