> On Mon, Feb 25, 2008 at 12:25 PM, Gollum <
zgo...@gmail.com> wrote:
>
> > I use form.clean() method to validate two fields of my form and I want
> > those fields to be empty when the form is shown again.
>
>
> Aside: as a user, I find forms that do this annoying, since I can no longer
> see what it is the form error is complaining about. Unless you are talking
> about blanking mis-matched obfuscated password fields, in which case it
> saves me the step of erasing what's already there that is already completely
> useless since I can't see it anyway.
>
>
> > The problem is I don't know how to set fields from clean() method
> > Setting cleaned_data['field1'] = '' and returning cleaned_data from
> > clean() method doesn't seem to work.
> >
>
> From:
>
http://www.djangoproject.com/documentation/newforms/#creating-form-instances
>
> "If you have a bound Form instance and want to change the data somehow, or
> if you want to bind an unbound Form instance to some data, create another
> Form instance. There is no way to change data in a Form instance. Once a
> Form instance has been created, you should consider its data immutable,
> whether it has data or not."
>
> Which sounds like you can't easily do what you want. Presumably you'd want
> to keep the error messages raised by validation, and any data that did
> validate. I guess you could cycle through the invalid form's _errors
> dictionary and remove those keys from (a copy of?) the