I override the __init__
method of my Form.
I can set the initial value by doing the following:
self.fields['fieldname'].initial = ....
But given that it is bound, calling the above has no effect. I tried doing this:
self.fields['fieldname'].bound_data = ....
but this does not work. Is there a way to do this ?
The is_valid() method is used to perform validation for each field of the form, it is defined in Django Form class. It returns True if data is valid and place all data into a cleaned_data attribute.
disabled. The disabled boolean argument, when set to True , disables a form field using the disabled HTML attribute so that it won't be editable by users. Even if a user tampers with the field's value submitted to the server, it will be ignored in favor of the value from the form's initial data.
cleaned_data is where all validated fields are stored.
You can update the form's data
dict
self.data['fieldname'] = new_value
bound_data
is a method, not an attribute, so you can't set the value there.
request.GET
and request.POST
are immutable, unless you create a copy()
. You could do the copy in your __init__
method, or before you bind the form.
data = request.POST.copy()
form = MyForm(data=data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With