WTForms: How to select options in SelectMultipleField?

后端 未结 5 1426
抹茶落季
抹茶落季 2020-12-24 07:54

Choices can be set using form.myfield.choices=[(\"1\",\"Choice1\"), (\"2\",\"Choice2\")]

What is the way to set the selected option?

5条回答
  •  清酒与你
    2020-12-24 08:29

    This is what worked for me on a SelectField:

    form.myfield.default = '1'
    form.process()
    

    I'm guessing you can just assign a list to form.myfield.default for a SelectMultipleField. The key, though, seems to be calling the process method on the form after you assign to default.

提交回复
热议问题