-
Notifications
You must be signed in to change notification settings - Fork 6.7k
A way to intercept tab change #2715
Comments
Hi, |
@DmitryEfimenko I see, I was hoping you could share some ideas, but it's ok. My workaround will be to disable all the other tabs as soon as current tab's form becomes "dirty". And then try to guide the poor user somehow to Save/Cancel when he desperately tries to get away from "the dirty tab" :-) |
@wojjas I could share some details. My flow of events is following:
here is some relevant code: Controller
Approximate code to display tabs in the view
Modal changesMade
modal view
This code is a bit simplified just to give you an idea. |
Hi, I have same problem. I use angular-unsavedChanges to prevent the user from leaving unsaved values. The proper use of this plugin is to configure your custom event which is fired when you would like to validate the $dirty - ness of your form.
Than in the tab definition you can fire this event:
When clicking on the tab the angular-unsavedChanges check if any form is dirty. If it is dirty (and user click on close in provided alert) it stop propagation of event:
This should stop the tab to be switched. This same approach works with ui-route |
Anyone solve this with angular-ui bootstrap? |
My workaround while working on a proper solution... 1. Load the following script after
|
@larvanitis thanks for the workaround! 👍 |
Closing this issue in favor of #4836 - this will be addressed when we fix the API for the tab component. |
While I no found a better solution more integrated with the tab component I'm using route events and form state to know when I should alert the user or not. I created a directive to do the hard job. |
I'm trying to intercept the tab change using the 'select' settings passing the $event (on the 'tab one') on this plunker - http://plnkr.co/edit/AKCezdOUVGM5tIUWWxJ6?p=preview -. |
@Salsao, you would be far better off asking for help via the methods outlined in our project documentation rather than commetngin on an issue from over two years ago. |
@Salsao, we don't allow you to prevent the default event from happening. You may feel free to file an issue requesting such a feature. I cannot guarantee that it will be added, but at the very least we will have a discussion. It's not a huge change on our end - it's more whether or not we want to support such a feature. When/if you decide to file the issue, please adhere to the issue template or your issue will be closed until it is followed. You might even try your hand at a possible fix via updating our tab plunker to respect the .preventDefault. |
* add ability for user to prevent currently selected tab's deselction by calling `$event.preventDefault()` in tab's `deselect` callback. Fixes angular-ui#5720 Addresses angular-ui#2715, angular-ui#4836, and angular-ui#5716.
* add ability for user to prevent currently selected tab's deselection by calling `$event.preventDefault()` in tab's `deselect` callback. Fixes angular-ui#5720 Addresses angular-ui#2715, angular-ui#4836, and angular-ui#5716.
@larvanitis, your solution works for me. I just had to change the 'tabDirective' to 'uibTabDirective'; Thank you! |
@andreas-andrade your fix helped me. Thanks! |
Hello,
I need a way to intercept a tab change. Here is a situation where such functionality would be useful:
I have two tabs. Each has a form inside. The requirement is that if form in the current tab becomes
dirty
, I need to show a popup message and depending on which option user chooses ((1) "save changes", (2) "discard changes", (3) "cancel") I should either (1) save and switch tab, (2) don't save and switch tab, or (3) don't save and stay on current tab.Please let me know if that functionality already exists. If it does not, what approach do you think would be most suitable?
The text was updated successfully, but these errors were encountered: