Validate WTForm form based on clicked button

前端 未结 1 1301
太阳男子
太阳男子 2020-12-18 14:22

On my form, I have two buttons that I use for submitting the form. One button deletes selected files (presented in a table, one checkbox to an object) and the other selects

相关标签:
1条回答
  • 2020-12-18 14:27

    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
    
    0 讨论(0)
提交回复
热议问题