Costy
Costy

Reputation: 165

WTForms Set input field after post

For below example:

Product(form):
   product = TextField('name')

If i set this field in GET action

form.product.data= "123",

render is "123". However, if i try set this value after POST action, i allways get value form POST

How can i set this value (rerender) after POST ?

Upvotes: 1

Views: 2635

Answers (2)

Costy
Costy

Reputation: 165

I wanted change only particulars fields, but rest keep from POST. I have noticed that data from POST has additional field "raw_data" and set form.product.data fiels hasn't done (re)render. Solution proved to be clear

form.product.raw_data = None 
form.product.data = 123 

render new value Maybe little bit "elegant" , but works !!!

Upvotes: 1

jibreel
jibreel

Reputation: 359

Are you asking how to clear form data from the form after a user has submitted it? In that case you could re-initialize the form

when you do

product = Product(request.POST)

It will fill the data that the user submitted.

product = Product()

This will clear the data.

Note: use 4 spaces for every line of the code, so it is displayed well.

Upvotes: 0

Related Questions