Is there any way to stop a tab from closing? I have a tab and I want to prevent the user from switching to another tab if the input fields on the tab are not valid.
I’ve tried a few experiments using on-deslect and an $on(’$destroy’) in the controller with out success.
We’re on the last tab (person icon). If the email is not valid I want to prevent the user from going to another tab.
The best I’ve been able to do was use a $on.($destroy) that reselected the tab again. But this incurs a controller destroy and recreation that I need to avoid (because user loses all edits)
I have form validation, but that alone does not achieve what I need.
I’ll have to use a modal popover to edit the details (I was trying to avoid this as it adds another screen and extra clicks for the user). With a modal I can enable/disable a ‘save’ button based on the form validity, thus forcing the user to complete the form correctly before leaving.
It appears there is no easy way to achieve this at a tab level (ie forcing a user to remain on a tab).
According to the official docs for ui-router (the state provider used for ion-tabs) You can specify a lot of stuff for Your state changes: UI-Router in depth
If You use $state.go(to [, toParams] [, options]) and then use the options location to set up Your condition:
location Boolean or “replace” (default true), If true will update the url in the location bar, if false will not.
This seems pretty complicated to implement, but I think this will let You avoid that lightbox
Or You could also catch the event when the change starts and then stop it if the form is not valid: State Change Events
When clicking onto a different tab, the tab changes, but the content of the tab does not load. – meaning it does not prevent the user from leaving a tab. It just stops the destination tab from loading its view.