Skip to Content
0
Jul 01, 2020 at 07:52 PM

sap.m.List - selectionChange - Data protection/data loss

261 Views

Hi there.

I've a master-detail app where the master view has a list and the detail view has an editable form. The navigation and all that works fine, but I've an issue with the data protection/data loss mechanism.

If I select item 1 in the master list, make some changes in the detail view, then press item 2 in the master list, I get a browser pop-up; "This page contain unsaved data..."

If I click OK, all is well. (This is handled in the display controller and irrelevant to this issue.)

If I click Cancel, the navigation to the selected list item is cancelled and the detail view is not changed. However; the list in the master now has the item I clicked highlighted, not the item that is still in the detail view.

In my Master view:

<List items="{/RecordSet}" selectionChange="handleSelectionChange" mode="SingleSelectMaster">
    <StandardListItem title="{Field1}" description="{Field2}" type="Navigation"/>
</List>

In my Master controller:

handleSelectionChange: function (oEvent) {
// Set the app's Dirty State. sap.ushell.Container.setDirtyFlag(this.getOwnerComponent().getModel().hasPendingChanges()); // Navigate to the selected item. This does not happen if SetDirtyFlag(true). this.getRouter().navTo("edit", { Id: oEvent.getParameter("listItem").getBindingContext().getProperty("Field3") ); }

Is there a way to prevent the sap.m.List highlighting the selected record when the navigation is cancelled?

I think I've looked myself blind on this issue, so I'm asking you people!

Thanks,
Thomas