-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(modal): Hook to prevent dismissal #1598
Comments
Yeh, I understand the use-case and it is valid. I'm not sure about the proposed API, though. Could you think of other alternatives and comment back here? |
Maybe copy Router API for CanDeactivate? https://angular.io/docs/ts/latest/guide/router.html#!#can-deactivate-guard Currently for our ui-router ng1 products, we have routes for Modals. If you go to I guess routing doesn't have to have anything to do with modals but just saying it works via routing at least :) |
@christarczon I have the exact same use-case: I have a form in a modal and I need to confirm they want to lose their changes, but I only want to show the confirmation if the form is dirty. Since |
@JWess I can't believe this was a year ago! No I never implemented with beforeDismiss, our design was changed. Disclaimer: Haven't tested this, it's mostly off the top of my head You'll need to have a reference to the form using ViewChild.
Modal from template: Modal from component: If you don't want to use the native confirm() you'll have to always return false then manually close the modal if they say OK. |
Awesome suggestion...really appreciate it! The only problem I have left is I end up with this error only in the case where ESC key is pressed and the form is dirty: I ended up with this code, which works, but generates the above error:
If you have any ideas on how to eliminate that error, I'd really appreciate it. |
I'd like a way to be notified when the user attempts to dismiss the modal using the Escape key or by clicking the backdrop. The use case is that they've filled in a form in the modal and I need to confirm they want to lose their changes.
My initial thought would be to add a beforeDismiss callback in NgbModalOptions that can return false to prevent the dismiss event. I can work on a PR if this sounds plausible.
The text was updated successfully, but these errors were encountered: