Text Box loses focus when clicking in a text Box on a new row - Lightswitch HTML RRS feed

  • Question

  • Hi All,

    I have my first major LightSwitch HTML app built and am going through and cleaning up some of the minor stuff that has been irritating me.

    The biggest of those is that if I click on a new row in a table by clicking on an editable Text Box, that Text Box gets focus but then loses it. this is forcing my users to have to click twice to enter data into a text box. Did some reading and possibly what is going on is that the first click selects the new row and the second click actually makes that Text Box editable.

    Is there a way to give the Text Box back it's focus after the new row has been selected? Or just automatically give the associated Text Box focus anytime a row is selected?

    I did not see any events that looked like "row selected" or "on click" or anything like that.



    Wednesday, December 14, 2016 9:21 PM


All replies

  • Hi Jeremy,

    I'm afraid it may involve a change to the msls script due to how the collection controls interpret taps as space keypress.  I've not done this so I cannot be sure it's the same as you're experiencing but...

    First try this Daves post render code on a single textbox:


    Then if that works,  you could take it a step further and prevent the focus issue by making these changes suggested by James Manning in the msls script:




    • Marked as answer by Jeremy Crouch Thursday, December 15, 2016 5:55 PM
    Thursday, December 15, 2016 3:27 AM
  • Thanks Josh, I will give those a try and post back my results.

    BTW, I am using msls-2.5.2.js. I googled a bit and found that there is a 2.5.3 version available... is that the latest version and should I even bother to upgrade? (I'm on Visual Studio Pro 2013, Version 12.0.40629.00 Update 5)



    Thursday, December 15, 2016 3:30 PM
  • It Worked!!! Honestly I had read that second article by James Manning and tried it but no luck.

    The reason? I was modifying my msls-2.5.2.js script, but my default.html was loading the msls-2.5.2.min.js! :



    I'm not 100% clear on what that minimized msls script is, or if its better to use it than the regular one, but in the minimized script all of the code is on 1 line and does not look easy to edit... so I just changed my default.html to load the regular one that I was editing and it works great now :) No more losing focus when selecting a new row!

    So one more ?: Is there any danger of using the non-min msls script? And if not what is the purpose of the min version anyway is the regular one works fine?

    Thanks, Jeremy


    I may have just found my own answer.. new to all this HTML/JavaScript programming (C# is so much simpler!lol) I found reference to JavaScript minifiers as a way to minimize your code. It looks like MS just did this to the msls.2.5.2.js file creating the min version. And I could do that myself to my modified version of the msls script. I'm just not sure of the benefits of doing this. Should I re-minimize my msls script?

    • Edited by Jeremy Crouch Thursday, December 15, 2016 4:07 PM new info
    Thursday, December 15, 2016 3:59 PM
  • Glad it worked.

    Minifying is a way of making the file smaller so the app loads faster.  We're talking milliseconds so no don't bother to re-min your script.  If you're gonna work in LS HTML, you'll soon find more reasons to modify the script.

    Thursday, December 15, 2016 6:03 PM