When the clean() method of my Django form detects an error, I’d like the form fields to redisplay as empty instead of filling in whatever input the user provided.
How do I do this? Is it a property of the form field itself, or is it done in the clean() method? I tried manipulating self.cleaned_data[‘fieldname’], but that did not work.
Thanks!
You need to set the data attribute of the field to ” in your clean method:
Hope that helps you out.
[Edit]
Here’s an expanded example that is working for me in Django 1.3.
[Edit]
Here’s an additional example that clears all fields if a condition isn’t met in a clean method. This works for me in Django 1.1.4.