Reselect a text bar every 5 seconds

I am writing a code for a barcode scanner that uses the node red dashboard to input data and one problem I'm having is that occasionally I will accidently click off the text bar and not notice. This causes all the scans that I do after this to not register. Right now I have a template node which successfully focusses me on the textbar each time I load the page, but I want it to load me back onto the text bar every 5 seconds or so. I've tried using a delay node with a loop but it doesn't seem to be working(See picture below). Is there any way to refocus on the text bar?

Thanks for any assistance!

Whoops forgot to attach the picture


You can use setInterval() in the ui-template node, that way the browser does all the work

Great, this should be what I'm looking for!

This may be a stupid question cus it's Monday morning and my brain probably isn't functioning fully yet, but how do I use this in the ui template node, I am using HTML to select the test bar but I am not too familiar with the language, or with the UI template node, so I'm not sure how to integrate this SetInterval() function

This is the code I am currently using:


Thanks for the help.

The simplest format would be something like this

   setInterval(() => { $("input:text:visible:first").focus(); },5000)

but something like this may be safer

document.addEventListener('visibilitychange', function() {
    if(document.hidden) {
        // tab is now inactive
        // temporarily clear timer using clearInterval() / clearTimeout()
    else {
        // tab is active again
        // restart timers
       var intervalNum = setInterval(() => { $("input:text:visible:first").focus(); },5000)

All untested.

Works great,

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.