Something wrong with wtforms FieldList && validation
Something wrong with wtforms FieldList && validation... It should say that field must have Int value, not This field is required Why f.data has [None, 2, None] value, not ['def', 2, 'abc'] ?
from webob.multidict import MultiDict
from wtforms import Form
from wtforms import FieldList, IntegerField
from wtforms import validators
class SearchForm(Form):
locality_id = FieldList(IntegerField(u'Locality', [validators.Req开发者_如何学Pythonuired()]))
d = MultiDict([('locality_id-0', 'def'), ('locality_id-1', 2), ('locality_id-2', 'abc')])
f = SearchForm(d)
print f.validate()
print f.errors
print f.data
print f.locality_id.data
% python form_test.py
False
{'locality_id': [[u'This field is required.'], [u'This field is required.']]}
{'locality_id': [None, 2, None]}
[None, 2, None]
It looks like there is a try... except
block in the IntegerField
ancestry which will place all non ints into the process_errors
property and that the class is specifically prevented from allowing you to have data populated with anything but valid data. I believe you can still get the values you seek in the raw_data
property, however.
精彩评论