Set Focus JS doesn't work in Millau 11.2 sandbox

  • 1
  • Problem
  • Updated 3 months ago
  • Solved
The below In-Line snippet works in Skuid version 9 but not in version 10 or 11. This is a "set focus" snippet that we use when using a scanner so the user doesn't have to manually put the cursor in the field. Does anyone know how to fix this?

var field = arguments[0];
$ = skuid.$;
var delay = ( function() {
    var timer = 0;
    return function(callback, ms) {
        clearTimeout (timer);
        timer = setTimeout(callback, ms);
    };
})();
delay(function(){
    $('.nx-field > input').first().focus();
    $('.nx-field > input').first().select();
}, 100 );

Photo of Tami Lust

Tami Lust

  • 5,280 Points 5k badge 2x thumb

Posted 3 months ago

  • 1
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,040 Points 10k badge 2x thumb
Hi Tami, my guess is that these lines may need to be updated to account for changes to the HTML structure or CSS classes between the two Skuid releases you're working with. 
$('.nx-field > input').first().focus();
$('.nx-field > input').first().select();

Also, if this is meant to run right on page load, I would make sure you wait until after the page is rendered before running this, because otherwise the above page elements may not yet exist when the script is running. Any easy way to try this chagne would be to trigger the snippet using an event-triggered action sequence, where the triggering event is the Skuid: page rendered event. Here's some info on that approach.
Photo of Tami Lust

Tami Lust

  • 5,280 Points 5k badge 2x thumb
Mark,

Thanks for your response. Making the following updates fixed the issue.

Updating:
$('.nx-field > input').first().focus();
$('.nx-field > input').first().select();

To:
 $('.nx-field input, .nx-field textarea, .nx-field .flex-text-wrap pre, .nx-field .nx-richtext-input').first().focus();
 $('.nx-field input, .nx-field textarea, .nx-field .flex-text-wrap pre, .nx-field .nx-richtext-input').first().select();


FYI: The snippet is not meant to be called on page load, it is called from within another snippet.

Thanks for your help!
(Edited)
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,040 Points 10k badge 2x thumb
Glad to hear this! And thank you for closing the loop on this conversation.