Focus on textInput after click on button.

Hi ! :wave:

What's the best way to get focus on text input ? I tried with javascript but nothing happened :

  observeEvent(input$ends_wrds, {
      updateTextInput(session, "user_seq",
                      value = paste(wrd_begin,input$ends_wrds))
      HTML("<script> const input = document.getElementById('user_seq');
            const end = input.value.length;
            input.setSelectionRange(end, end);
                        input.focus(); </script>")
  })

The idea is to focus on a text input after an update of this input.
Regards.

Solution :

I write a file named focus.js and this file was loaded in ui part with tags$script(src = "focus.js"),.

In this focus.js :

document.getElementById("user_seq").onchange = function() {doThing()};

function doThing(){
  document.getElementById("user_seq").focus()
}

That was easy.

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.