WTForms: How to select options in SelectMultipleField?

后端 未结 5 1418
抹茶落季
抹茶落季 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-24 08:20

    Cheers guys for your help. I tried the last answer and it did not work for me. With a call to the process method it works and what you can do is just use it and pass to its data argument the data you don't want to be reset. So something like this:

        form.process(data={k: v for k, v in request.form.items() if 
        k=='your_form_item_name'})
    

提交回复
热议问题