locked
Force discard button to confirm close if there are unsaved changes (HTML Client Dialog) RRS feed

  • Question

  • Hi,

    Is there a way to force the discard button in a Dialog screen to confirm close if there are unsaved changes? (for all Visual Collections in the screen). By default, if you have Tabs in your add/edit screen, add a few records and then tap the Discard button, the dialog is closed without warning, and the new records are not saved.

    thank you.

    Nico.

    Monday, March 10, 2014 7:55 PM

All replies

  • Unfortunately the current version of the LS HTML client at the time of writing does not support this. Hopefully it will be added in a not too distant future release.

    The only way to get it to work at the moment would be to "hack" the msls-2.5.0.js file. I've experimented with adding the following to the discardChanges() function: 

    function discardChanges(navigateBackOption) {
        var me = this;
    
        // begin custom code
        if (me.activeNavigationUnit.hasChanges) {
            if (!confirm('Do you want to lose all changes?'))
                return false;
        // end custom code
    
        ...
    }

    However, the above only works if you use your own button to exit the dialog or screen and hide the default close button. I was not able to find a way to hook into the default close button, but with some more digging it will be possible.


    Regards, Xander. My Blog

    • Proposed as answer by sbarash Wednesday, May 20, 2020 7:59 PM
    Wednesday, April 16, 2014 8:43 AM
  • Hey Xander. Thank you for your helpful reply. Hopefully, we can raise some awareness among the LightSwitch Team and the LS gurus (we know who they are), maybe tweeting this post?. It would be a good feature, improving the UX and it's a default in the desktop client.
    Wednesday, April 16, 2014 1:52 PM