Posted By

tclancy on 05/13/11


Tagged


Versions (?)

Add Class to All Error Fields in Form


 / Published in: Python
 

URL: http://stackoverflow.com/questions/5339288/rendering-required-and-error-classes-with-django-form-fields-in-a-custom-templat

  1. def __init__(self, *args, **kwargs):
  2. super(form, self).__init__(*args, **kwargs)
  3. for field in self.errors:
  4. if not field == '__all__':
  5. # errors dict can have key __all__ for non field errors.
  6. self.fields[field].widget.attrs['class'] = \
  7. self.fields[field].widget.attrs.get('class', '') + 'error'

Report this snippet  

You need to login to post a comment.