Adding css class to field on validation error in django

Myth picture Myth · Jan 31, 2011 · Viewed 17.1k times · Source

I am using Django's modelform and its really good. How can I highlight the actual text box (e.g. border:red ) if there is a validation error associated with it. Basically what i want is to add a class (error) if there is a validation error to a field.

Answer

errx picture errx · Jan 31, 2011

What about defining error_css_class? http://docs.djangoproject.com/en/dev/ref/forms/api/#styling-required-or-erroneous-form-rows?

class MyForm(ModelForm):
    error_css_class = 'error'