Our implementation of click_button assumes a little too much when it's preceded by a fill_form (meaning we have an "active form").
We assume that if you're clicking a button you're trying to submit the active form. But it could be equally true that we're cancelling the form (or as our Live test shows, that you're resetting the form, or in the case of our Static test that you're just clicking a completely different button).
So... we have to make our errors a little less helpful but allow for a better experience.
Instead of validating that the button is a submit button and raising if it isn't (which is actually confusing if you're trying to, say, cancel a form submission -- "of course it's not submit button! We're cancelling the form!"), we now check if the button you're clicking is a submit button for the form. If it isn't, we follow down the regular button click path -- assuming phx-click in LiveView and a single button form submission in Static.
What changed?
Our implementation of
click_button
assumes a little too much when it's preceded by afill_form
(meaning we have an "active form").We assume that if you're clicking a button you're trying to submit the active form. But it could be equally true that we're cancelling the form (or as our Live test shows, that you're resetting the form, or in the case of our Static test that you're just clicking a completely different button).
So... we have to make our errors a little less helpful but allow for a better experience.
Instead of validating that the button is a submit button and raising if it isn't (which is actually confusing if you're trying to, say, cancel a form submission -- "of course it's not submit button! We're cancelling the form!"), we now check if the button you're clicking is a submit button for the form. If it isn't, we follow down the regular button click path -- assuming
phx-click
in LiveView and a single button form submission in Static.