Search code examples
htmlvisual-studio-lightswitchlightswitch-2012

How to detect add or edit mode in HTML5 Lightswitch client?


How do you detect if, when using LightSwitch, the detail page is in Add or Edit mode?

I want to change the title of the screen from AddEdit Customer to either 'Add Customer' or 'Edit Customer'.

I can get screen.detail.dispayName = "Something". i need to know how to detect if it is in Add or Edit mode.


Solution

  • This is valid for HTML5 lightswitch -

    There is Javascript namespace "msls" which encapsulates the LightSwitch JS framework to obtain the equivalent of EntityState.

    The intellisense does not work so well, so if you keep getting screen.(nothing), add the following:

    /// <reference path="../GeneratedArtifacts/viewModel.js" />
    

    On the main event, add:

    myapp.Customer.created = function (screen) {
        if (screen.Customer.details.entityState == msls.EntityState.added) {
            screen.details.displayName = "Add Customer";
        } else {
            screen.details.displayName = "Edit Customer";
       }
    }
    

    where Customer is the dataset for the AddEdit HTML5 Lightscreen page.