Reputation: 1602
so I have this code
class ItemPurchaseForm(wtforms.Form):
purchase_price = IntegerField(label='Purchase Price: ',
validators=[InputRequired()])
def validate(self, *args, **kwargs):
if not super().validate():
self.purchase_price.errors += (super().errors,)
return False
#.... do other validations....
class PurchaseTransactionForm(Form):
yyyy = IntegerField(label='Transaction Year',
validators=[InputRequired()])
transaction_items = FieldList(FormField(ItemPurchaseForm),
label='Purchased items',
min_entries=1)
submit_button = SubmitField(label='Add new purchase transaction')
def validate(self, **kwargs):
if not super().validate():
self.yyyy.errors += (super().errors, 'super not validated')
return False
#.... do some other validation
As you can see there is a FieldList(FormField(...))
, so I followed this answer to fix previous error caused by CRSF field. And now if I have def validate()
in ItemPurchaseForm
it will give me error, and the error is just this: {'transaction_items': [{}]}
.
If I remove the def validate()
from ItemPurhcaseForm
, everything works well. Is there any reason why that causes error? I did read this http://wtforms.readthedocs.org/en/latest/fields.html#wtforms.fields.Field.validate, so does it mean that ItemPurchaseForm
is a Subfield?
Upvotes: 2
Views: 1179
Reputation: 1602
I know the problem and have fixed the problem. I just forgot to put return True
in ItemPurchaseForm validate()
Upvotes: 2