Validate WTForm form based on clicked button

百般思念 提交于 2019-11-29 08:48:22

The key thing to note about buttons in HTML is that only the button that was pressed sends its data back to the server. So you can just check if the button's data field is set using if form.process_button.data an things will work in the general case.

In your particular case, since both of your buttons pull their data from the same underlying parameter name (action) you will need to check that the data in one of your button fields is what you would expect:

def validate_files(form, field):
    # If the ButtonFields used different names then this would just be
    # if form.process_button.data:
    if form.process_button.data == ProcessForm.PROCESS:
        # Then the user clicked process_button
    else:
        # The user clicked delete_button
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!