On Thu, 2007-06-14 at 15:15 +0200, Michal wrote:
> Hello,
> is there any way how to set a value to FormField during clean_<field> 
> method?
> 
> I have registration form on my site. There is obvious fields like 
> username, email, and 2 fields for passwords. After submiting the form I 
> validate it, and if there is some error, I would like to set both 
> password fields to "" (because I don't want show to the world, what 
> password user want to set).
> 
> Is there any chance, that I could do this during validation of data? (I 
> try to set self.cleaned_data['password1']='' during clean_<field> method 
> and also clean method of the form, but without success).

Modifying cleaned_data for other fields is probably a bit fragile in
clean_<field> methods. For a start, you can only hope to succeed if
those other fields were cleaned before your field, which means the
ordering of fields is a constraint.

A more logical (in terms of the design of newforms data cleaning) place
to do multi-field validation and cleaning is the form's clean() method.
At that point, you have full access to cleaned_data (in fact, it's what
that method returns) and the _errors dictionary so you can see if any
fields have errors and, if so, clean out (or just remove the keys) for
the password fields.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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