Search code examples
visual-studio-lightswitchlightswitch-2013

LightSwitch Open another screen when adding a new 'User'


I have been working with VS LightSwith for a couple of days, and I have this question: If I have a DB table of 'Users' in witch I can add or edit an user trough a LightSwitch screen, and that table is connected to another for 'Roles' in witch each user can have 0 or n roles, it is possible to open the Roles screen for that user only when a new user is added but not when is edited? The User table has an Id that is foreign key for the Roles one.


Solution

  • if I have understood the question right, the simplest way to solve this would be to have 2 separate screens, 1 Add and 1 Edit, alternatively i would assume the user must enter a name, and this cannot be null, if you added code on the screen created method to hide the Roles table if the name is null then this should do the trick, for example:

    myapp.Staff.created = function (screen) {
        if(screen.Staff.firstname == null) {
           screen.findContentItem("Roles").isVisible = true
        }
        else {
           screen.findContentItem("Roles").isVisible = false
        }
    };
    

    you can implement the validation to control whether a field can/cannot be null on either the beforeApplyChanges code block or on a custom save button

    hope this helps, if you have any more questions feel free to ask