mobiscroll icon indicating copy to clipboard operation
mobiscroll copied to clipboard

Allow Listview's onNavStart handler to prevent navigation

Open aschwartz-satcom opened this issue 10 years ago • 1 comments

With most routing/navigational frameworks, you are given an opportunity to prevent navigation on an "onNavStart"-style event.

There does not appear to be any way to do this with the ListView.

In my case (using Angular), I'm using the ListView to provide hierarchical navigation in a modal.

For the terminal states, I assign a bogus "children" collection (something like "children: [{}]" ). When the user reaches one of these terminal states, I adjust the height of the listview so that only the "Back" button is visible. At the same time, a directive that contains the markup and logic for that particular terminal state's interface is ngIf-ed into the DOM.

One of the states has a "save" button, and is supposed to prompt/nag you if you have unsaved changes when you hit the Listview's "Back" item. Without the ability to prevent navigation, I have to resort to hacks (like attempting to undo the user's navigation by re-navigating to the appropriate terminal view from the onNavStart handler).

aschwartz-satcom avatar Jan 12 '16 19:01 aschwartz-satcom

This can be actually done by returning false in the onItemTap event. (I just updated the docs, see: http://docs.mobiscroll.com/2-17-1/listview#!event-onItemTap).

Example:

onItemTap: function (item) {
    if (item.hasClass('mbsc-lv-back') /* && some other condition */) {
        return false;
    }
}

dioslaska avatar Jan 13 '16 08:01 dioslaska