locked
Value change of the custom property in the viewmodel RRS feed

  • Question

  • Hi

    I'm using LightSwitch HTML client with VS2012 Update 2.

    In my screen designer I have created a new property of boolean type. Now I want to write some custom code when this property value is true.

    The scenario is something like this

    After the user has key in data in Address field , There will be a flipswith next to this textbox which is binded to my custom boolean property. When this is set to true I want the permanentAddress field should also get the same value as Address field.

    I think it is a quite common scenario and I'm sure this could be easily achieved in LightSwitch

    Please help.

    Monday, April 22, 2013 12:58 PM

Answers

  • Hi,

    In your screen's created code, you can use addChangeListener to add an event handler and do what you need.

    For example

        screen.addChangeListener("SameAsAddress", function () {
            if (screen.SameAsAddress) {
                // Copy address to permanent address.
            }
        });

    Replace SameAsAddress with the name of your Boolean Screen Property.

    Best regards,
    Huy Nguyen


    Monday, April 22, 2013 4:49 PM

All replies

  • Hi,

    In your screen's created code, you can use addChangeListener to add an event handler and do what you need.

    For example

        screen.addChangeListener("SameAsAddress", function () {
            if (screen.SameAsAddress) {
                // Copy address to permanent address.
            }
        });

    Replace SameAsAddress with the name of your Boolean Screen Property.

    Best regards,
    Huy Nguyen


    Monday, April 22, 2013 4:49 PM
  • Hi Huy

    Thanks for the help , it worked.

    I want to know what are the other listener events that can be attached to these viewmodel properties. Is it possible to attach keypress event. Is there any documentation on msdn for the same ? Thanks for your help.

    Regards

    Goldy

    Wednesday, April 24, 2013 11:48 AM
  • Hi Goldy,

    I'm afraid there is no comprehensive lists of events for LightSwitch JavaScript runtime. Going through the HTML Client MSDN page and the LightSwitch team blog articles (for example this one about the API) may help you find what you need.

    In general, any properties on a screen or an entity object will be an observable property, so that you can listen to their change notifications.

    Since you have access to full source code of LightSwitch JavaScript library (msls-1.0.0.js under Scripts folder), here's another way to explore the events: If you search for msls_observableProperty or msls_event, you will find them on class definitions. For example you can see this

        msls_mixIntoExistingClass(_DataWorkspaceDetails, {
            hasChanges: msls_observableProperty(null, hasChanges_get),
            hasNestedChangeSets: msls_observableProperty(null, hasNestedChangeSets_get),
    
            getChanges: getChanges,
            _findModel: _findModel,
    
            contentchange: msls_event()
        });

    That woud indicate that the DataWorkspaceDetails class (myapp.activeDataWorkspace.details is an instance of this class) exposes 3 events:

    • hasChanges and hasNestedChanges are property change notification and can be listened to using addChangeListener("hasChanges", handler).
    • contentchange is a generic event that can be listened to using addEventListener("contentchange", handler).

    Best regards,
    Huy Nguyen

     

    Wednesday, April 24, 2013 4:06 PM