Dojo MVC: How to cancel View Transition on Data Error

92 views Asked by At

I am using Dojo 1.10 for SPA. In the application I have a view, instance of dojox/app/view that allows the user to manipulate data loaded from model. The view has a Back button which allows the user to transition to Home screen.

The handler of the Back button uses

        TransitionEvent({
            app: self.app,
            target: evt,
            transitionOptions: {
                history: true,
                params: {...},
                title: "ViewListView",
                target: "ViewListView",
                url: "#ViewListView"
            },
            triggerEvent: evt
        }).dispatch();

to transition back to Home screen.

The use case here is that the user should be warned before transition, if there's Unsaved Data Changes. User should be presented with options to discard changes and proceed with transition or cancel the transition and remain on the same view in order to be able to Save changes.

This can be achieved in the handler of Back button because the transition is manually triggered and can be prevented to occur if user opts to Save changes before going back. The problem is, when user presses the browser back button, the transition happens internally and can't be caught to check if there are any Unsaved Data Changes and stop the transition to happen.

I've tried using:

beforeDeactivate(nextView, data) is called before the view is hidden each time it is being transitioned out.

but couldn't find a way to intercept the transition. How can I intercept the transition before occurring to apply checks? Is it possible to intercept the transition in a place so that it captures both, transition from browser back button and transition manually triggered from within the view?

Thanks for your help.

1

There are 1 answers

0
edchat On

It should not be hard to extend the History controller to support the check to avoid doing the transition if there is unsaved data.