On Mon, Feb 25, 2008 at 12:25 PM, Gollum <[EMAIL PROTECTED]> 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
request.POSTdictionary, instantiate a new form using the stripped-down
POST dictionary,
copy over _errors from the invalid form to the new one, and then display the
result.  Seems pretty hackish, though, which is likely an indication that
either I'm missing the elegant way to do it, or it is not something Django's
forms were designed to do.

Karen

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to