[英]WTForms FieldList required Optional validation
Currently I'm using Flask with WTForms via Flask-WTForms but being stuck with FieldList. 目前我正在通过Flask-WTForms将Flask与WTForms一起使用,但仍然坚持使用FieldList。 I use FieldList for a list of email address like this: 我使用FieldList获取电子邮件地址列表,如下所示:
class MailToForm(Form):
emailAddress = StringField(
'Email',
validators=[
validators.DataRequired(),
validators.Email()
]
)
Then I have another form to use it above form: 然后我有另一种形式在形式上使用它:
class JobForm(Form):
name = StringField('Name',
validators=[
validators.DataRequired()
])
annotation = TextAreaField('Annotation')
emails = FieldList(FormField(MailToForm),
'Send Result To',
min_entries=1)
The problem here is that when I submit the form with all valid data the validate_on_submit
function won't return True
if I not pass a new Optionals
validation for emails
field in JobForm
. 这里的问题是,当我提交包含所有有效数据的表单时,如果我没有为JobForm
emails
字段传递新的Optionals
验证,则validate_on_submit
函数将不会返回True
。 But then the form will valid event if I pass invalid data to emailAddress
. 但是如果我将无效数据传递给emailAddress
那么表单将是有效事件。
Please help me on this! 请帮帮我!
I got how to get away with this. 我得到了如何摆脱这个。 I have to add the WTF's hidden fields of subforms so it can be validated. 我必须添加WTF隐藏的子表单字段,以便进行验证。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.