locked
Cascading modal pickers and change listeners RRS feed

  • Question

  • Hi there,

    I'm struggling a bit getting a solid cascading modal picker working, I've got the picker working OK following this pattern:

    • Select a Customer from a modal picker (an unrelated field).
    • Filter the options in the Project and CustomerLocation modal pickers based on the customer.

    This approach works fine, except when I go into edit the record. As the Customer is unrelated, it isn't populated when I go back in to edit. Looking around the internet, it looks like I need a change listener that blanks out the Project and CustomerLocation when the Customer is changed. This is the code I've got so far:

    myapp.AddEditProjectEvent.created = function (screen) {
        // Write code here.
    
        screen.ProjectEvent.addChangeListener("Customer", CustomerChanged);
    
        // Clean up when screen is closed.
        screen.details.rootContentItem.handleViewDispose(function () {
            screen.ProjectEvent.removeChangeListener("Customer", CustomerChanged);
        });
    
    };
    
    function CustomerChanged(e) {
    
        msls.showMessageBox('Customer Changed', { title: 'Customer Changed' });
    
        //screen.findContentItem("Project").value = "";
        //screen.findContentItem("CustomerLocation").value = "";
    
    };

    This doesn't error when changing the Customer, but it also doesn't raise the message (or blank out the other two modal pickers when they're not commented out). Any pointers as to where I'm going wrong would be much appreciated.


    • Edited by daveyboyh Sunday, January 11, 2015 6:39 PM
    Sunday, January 11, 2015 6:38 PM

Answers

  • Hi Dave, I'm not sure to understand...when you say that Customer is an unrelated field do you mean that it's not a navigation property of your ProjectEvent entity? (i.e. the customer content item is bound to a local property in your viewmodel)

    If it's a screen local property then your addChangeListener can't work because "Customer" is not a name of a property that belongs to ProjectEvent.

    I think you just should add the listener to the screen

    screen.addChangeListener("Customer", CustomerChanged);

    Additionally, take a look to this link about clearing a modal picker and check if it can be of any help.


    Marco

    • Proposed as answer by joshbooker Monday, January 12, 2015 4:01 PM
    • Marked as answer by daveyboyh Tuesday, January 13, 2015 10:12 AM
    Monday, January 12, 2015 11:24 AM

All replies

  • This doesn't error when changing the Customer, but it also doesn't raise the message (or blank out the other two modal pickers when they're not commented out).

    Hi daveyboyh,

    We can find and fix errors that occur in the code that you write by debugging your application. There are, however, errors that can occur outside the code that you write. For example, there are many issues that could prevent your application from communicating with a server. Please enable diagnostics in your lightswitch application, and check whether it can give some hints why this happens.

    Best regards,

    Angie


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Angie Xu Monday, January 12, 2015 8:18 AM
    Monday, January 12, 2015 8:18 AM
  • Hi Dave, I'm not sure to understand...when you say that Customer is an unrelated field do you mean that it's not a navigation property of your ProjectEvent entity? (i.e. the customer content item is bound to a local property in your viewmodel)

    If it's a screen local property then your addChangeListener can't work because "Customer" is not a name of a property that belongs to ProjectEvent.

    I think you just should add the listener to the screen

    screen.addChangeListener("Customer", CustomerChanged);

    Additionally, take a look to this link about clearing a modal picker and check if it can be of any help.


    Marco

    • Proposed as answer by joshbooker Monday, January 12, 2015 4:01 PM
    • Marked as answer by daveyboyh Tuesday, January 13, 2015 10:12 AM
    Monday, January 12, 2015 11:24 AM
  • Ahh, that makes perfect sense.

    Thanks for your help Marco.

    Tuesday, January 13, 2015 10:19 AM