shadcn Dialog - "submit" vs "cancel"

I am working with a shadcn dialog and I want to execute different functionality when different actions happen. Specifically, I have a form in the modal and I have a save button, which I obviously want to make an API call. However, you can also close the modal by clicking on the backdrop and the built in close button. I want to be able to reset my form when I select the backdrop/close button and execute the API call on click of the save button. As far as I know, theres no way to distinguish between the method of closing the Dialog, any ideas?
1 Reply
tyler4949
tyler4949OP16h ago
I have this post on the github for more info: https://github.com/shadcn-ui/ui/discussions/5588
GitHub
Distinguish between manual close vs cancel of Dialog component · sh...
I have a Dialog with a form inside using TanStack Form. I have an apply button which essentially just closes the modal. However I would like to reset the form when either clicking the Dialog close ...

Did you find this page helpful?