Setting a form field's valule during validation
Posted
by LaundroMat
on Stack Overflow
See other posts from Stack Overflow
or by LaundroMat
Published on 2010-05-17T18:57:27Z
Indexed on
2010/05/17
19:00 UTC
Read the original article
Hit count: 115
Hi,
I read about this issue already, but I'm having trouble understanding why I can't change the value of a form's field during validation.
I have a form where a user can enter a decimal value. This value has to be higher than the initial value of the item the user is changing. During clean(), the value that was entered is checked against the item's previous value. I would like to be able to re-set the form field's value to the item's initial value when a user enters a lower value.
Is this possible from within the clean() method, or am I forced to do this in the view? Somehow, it doesn't feel right to do this in the view...
(To make matters more complicated, the form's fields are built up dynamically, meaning I have to override the form's clean() method instead of using the clean_() method).
Thanks in advance!
© Stack Overflow or respective owner