73

Remove django form field validation errors manually

 3 years ago
source link: https://blog.mathieu-leplatre.info/remove-django-form-field-valiation-errors-manually.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Remove django form field validation errors manually

Remove django form field validation errors manually

Tue 06 December 2011

Original post at Makina Corpus

Sometimes I look for something which seems so simple and stupid that I can't imagine it does not exist. It makes me wonder why and who is the fool. Worse, I can't be sure about my search keywords to prove me anything.

I just wanted to delete, reset or remove the validation errors of a single form field, within a django view, without overriding the form or field class.

A one-liner

aform.errors['afield'] = aform['afield'].error_class()

That's it folks !

  • This will not affect other fields errors or non-field errors ;
  • This will reuse nicely the field error class (ErrorDict or ErrorList) ;
  • You cannot set aform.errors['afield'] = None or your form full_clean() will be performed again !
  • Obviously, the ideal approach is to override your form clean() properly.

#django, #tips - Posted in the Dev category


© Copyright 2020 by Mathieu Leplatre. mnmlist Theme

Content licensed under the Creative Commons attribution-noncommercial-sharealike License.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK