locked
LightSwitch HTML Client - Select Modal Picker value from code RRS feed

  • Question

  • Hi!

    I would need to select item in a Modal Picker from JS. I got value in DOM.

    Can somebody give me a hint or example how to do it?

    Thank you for your time!

    Tuesday, May 7, 2013 1:30 PM

Answers

  • Hi,

    Just to make sure, you are using a Details Modal Picker to pick a Year - not a Dropdown or a custom <select> html element. Would you mind posting a screenshot of your screen on the Screen Designer?

    It sounds to me like you want to solve the issue of initializing certain values when adding a new entity. If it's the case, an easier solution is to actually write code in the entity's created method and use the application's data workspace to query for the default entity. Let's take Northwind for example, here's how you can write code that will initialize the Customer property of an Order to the first Customer.

    On the Entity Designer, change the perspective (bottom) to HTML Client, then write code for the created method

    myapp.Order.created = function (entity) {
        myapp.activeDataWorkspace.Northwind
            .Customers.top(1)
            .execute().then(function (result) {
                if (result.results.length > 0) {
                    entity.Customer = result.results[0];
                }
            });
    };

    But I'm not sure if you actually have a separate entity type representing years in your application. So I would like some further information for this.

    Best regards,
    Huy

    • Marked as answer by Zorčec Wednesday, May 15, 2013 1:08 PM
    Friday, May 10, 2013 7:34 AM

All replies

  • Hi,

    The Modal Picker is bound to an entity's navigation property, for example you can have a Modal Picker bound to an Order's Customer. Once an item in the Modal Picker is selected, it will simply set the navigation property to that value.

    Looks like to me your intention is to set the Order's Customer by selecting an item from the Modal Picker. If it's the case, you can just set the underlying order.Customer to a Customer that you query from the server.

    If that's not your intention, can you describe your scenario in more details?

    Best regards,
    Huy

    Thursday, May 9, 2013 8:15 PM
  • Thank you on your answer...

    I got Modal picker for picking year-date (custom format retrieved via WCF). I need to select default value by current date which id/position isn't always the same.

    Maybe I could create item identical to item I wish to pick and then put it into Modal Picker selectedItem property?

    Ty

    Friday, May 10, 2013 6:39 AM
  • Hi,

    Just to make sure, you are using a Details Modal Picker to pick a Year - not a Dropdown or a custom <select> html element. Would you mind posting a screenshot of your screen on the Screen Designer?

    It sounds to me like you want to solve the issue of initializing certain values when adding a new entity. If it's the case, an easier solution is to actually write code in the entity's created method and use the application's data workspace to query for the default entity. Let's take Northwind for example, here's how you can write code that will initialize the Customer property of an Order to the first Customer.

    On the Entity Designer, change the perspective (bottom) to HTML Client, then write code for the created method

    myapp.Order.created = function (entity) {
        myapp.activeDataWorkspace.Northwind
            .Customers.top(1)
            .execute().then(function (result) {
                if (result.results.length > 0) {
                    entity.Customer = result.results[0];
                }
            });
    };

    But I'm not sure if you actually have a separate entity type representing years in your application. So I would like some further information for this.

    Best regards,
    Huy

    • Marked as answer by Zorčec Wednesday, May 15, 2013 1:08 PM
    Friday, May 10, 2013 7:34 AM
  • Thank you, I was looking for this to set the default values on a modal picker.

    How would I reference a query to select the first item, instead of just the table's first item?  For example, if I had a SortedCustomers query under the Customers table, how would I get that first item from the sorted list:

    .Customers.SortedCustomers.top(1) doesn't seem to work,

    .SortedCustomers.top(1) doesn't hit the mark either.

    Thank you for any pointers you can give me.


    Louis-EY

    Wednesday, May 15, 2013 3:05 AM
  • Hi,

    To execute a custom server query, you can use myApp.activeDataWorkspace.MyDataSource.MyCustomServerQuery([any parameters]). For example, if I have a custom server query called CustomersByCountry, here's how I would get the first Customer from France.

        myapp.activeDataWorkspace.Northwind
            .CustomerByCountry("France")
            .top(1)
            .execute()
            .then(function (result) {
                var c = result.results[0];
            }, function (error) {
                msls.showMessageBox(error, {
                    title: "Load error"
                });
            });
    Best regards,
    Huy
    Wednesday, May 15, 2013 4:23 PM
  • Hi,

    What should I do when I want to initialize Details Modal Picker with a local property?


    Friday, November 15, 2013 2:08 PM