locked
Parameter availability on Mobiles/tablets RRS feed

  • Question

  • Hi,

    I have been developing an LS2013 html app for approx 30 users. It test well under development and on desktop browsers. However I have noticed that on non-desktop devices screen (local) property completed by a users are only available to other processes after the screen property (text box) has lost the focus. For example, if we have a simple screen with a property "Prop_NewNote" and an "Add  Note" button that adds a simple record to the database with the value of Prop_NewNote as one of the columns. On PCs when we push "Add Note" the property Prop_NewNote is available to the process that adds the record. However on mobiles if the property (screen text box) still has the focus when we push "Add Note" then Prop_NewNote will be null. If however we take the focus off (screen text box) by clicking on something else and then pushing "Add Note" the properties value is available

    We have a number of screens that allows a user to push an "Add button" without an intermediary step.

    Im assuming that there is something really simple that I am missing as I cant be the first person to be stuck with this issue so any help would, as always be greatly appreciated...

    Thanks

    Adam

    Friday, August 7, 2015 3:53 PM

Answers

  • Hi acgt1008,

    It seems that the TextBox doesn't get the entered value when you click "Add Note" button without clicking on something. Please try with following code to update the TextBox control's binding targets as PropertyChanged.

    myapp.AddEditCustomer.Name_postRender = function (element, contentItem) {
        contentItem.dataBind("_view.isRendered", function (isRendered) {
            if (isRendered) {
     
                var tb = contentItem._view.underlyingControl;
                tb.getView().on("keyup", ".id-element", null, function (e) {
                    tb.text = tb._textElement.val();
                });
     
                contentItem.dataBind("value", function (value) {
                    // Use the toastr library from nuget (http://www.nuget.org/packages/toastr)
                    // in order to display the value of the updated binding target 
                    // and demonstrate that the update occurs on PropertyChanged 
                    toastr.info("value [" + value + "]"); 
                });
            }
        });
    };

      




    Best Regards,
    Weiwei

    • Marked as answer by acgt1008 Thursday, August 13, 2015 11:04 AM
    Monday, August 10, 2015 8:28 AM
    Moderator

All replies

  • Hi acgt1008,

    It seems that the TextBox doesn't get the entered value when you click "Add Note" button without clicking on something. Please try with following code to update the TextBox control's binding targets as PropertyChanged.

    myapp.AddEditCustomer.Name_postRender = function (element, contentItem) {
        contentItem.dataBind("_view.isRendered", function (isRendered) {
            if (isRendered) {
     
                var tb = contentItem._view.underlyingControl;
                tb.getView().on("keyup", ".id-element", null, function (e) {
                    tb.text = tb._textElement.val();
                });
     
                contentItem.dataBind("value", function (value) {
                    // Use the toastr library from nuget (http://www.nuget.org/packages/toastr)
                    // in order to display the value of the updated binding target 
                    // and demonstrate that the update occurs on PropertyChanged 
                    toastr.info("value [" + value + "]"); 
                });
            }
        });
    };

      




    Best Regards,
    Weiwei

    • Marked as answer by acgt1008 Thursday, August 13, 2015 11:04 AM
    Monday, August 10, 2015 8:28 AM
    Moderator
  • Thanks for this, it worked a treat when adding new note, much appreciated thanks. However the same problem manifests itself when I added a Search button to a bound text property (I didnt include it in the initial request so as to keep my question short and clear).

    I have a simple search form with a text box, a bound result query and a Search button. The search button has no code but is included for various UI reasons. When the user  enters text in the text box then pushes the search button the fact that the text box loses the focus means that the query runs. This works fine on a desktop browser, however on mobiles again the value of the text box is not available (its null) until the text box loses focus (something that dosnt happen on mobiles).

    If I use the (very useful) function you provided the query will now be run after every keystroke, something that is very inefficient (in our circumstance). Is there any other approach or standard design pattern you might be able to suggest?

    Thanks again for your help

    Adam

    Monday, August 10, 2015 11:33 AM
  • Hi acgt1008,

    Please try with custom control and data bind. We can create our own customer which used to implement the function you want. Then add it into our LightSwitch HTML application. Following blog introduces custom control and data bind in LightSwitch HTML application, hope it can help you.
    http://blogs.msdn.com/b/lightswitch/archive/2012/12/06/custom-controls-and-data-binding-in-the-lightswitch-html-client-joe-binder.aspx
     
    Best Regards,
    Weiwei

    Tuesday, August 11, 2015 6:20 AM
    Moderator
  • I might be totally wrong here, but I wonder whether it is a classic timing issue that you are experiencing here. If you implemented the Add button event handler yourself, try and wrap the code inside of a setTimeout(function(){...}) function to see whether that perhaps helps to ensure that the LS property values are set before the add button code is executed. First try with the default timeout value and if that does not work, try say 500 ms. I think it might be worth a shot...

    Regards, Xander. My Blog

    Tuesday, August 11, 2015 8:11 AM
  • Xander, that is my thinking too, may only need 100ms just to let the other events to process. Does not look like the event execution sequence is exactly the same or the javascript multi-threading capability on said devices may be less.

    Dave


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    Wednesday, August 12, 2015 9:34 AM
  • A timing issue was one of my first thoughts as well so initially I tried a setTimeout function. However this made no difference (no matter what delay I built in) as it seems the property value is only "released" after the control (for that property) loses the focus. Its a strange one!

    Wednesday, August 12, 2015 4:09 PM
  • Have you tried checking for the existence of a value in Prop_NewNote in your AddNote button's CanExecute() function? something like:
    myapp.SomeScreen.AddNote_canExecute = function (screen){
        if(!!screen.Prop_NewNote) {
            return true;
        } else {
            return false;
        };
    };

    Just a thought...
    Monday, August 17, 2015 7:53 PM