How can I make ENTER act like TAB, i.e. when user presses ENTER in an input field, the cursor jumps to the next field, just as would happen by pressing the TAB key?
Asked
Active
Viewed 219 times
1 Answers
0
See an example below:
library(shiny)
library(shinyjs)
# Define UI for application that draws a histogram
ui <- fluidPage(
useShinyjs(),
sidebarLayout(
sidebarPanel(
textInput("txt1", "Text: "),
textInput("txt2", "Text: ")
),
mainPanel()
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
observe({
runjs("
var inputs = $(':input').keypress(function(e){
if (e.which == 13) {
e.preventDefault();
var nextInput = inputs.get(inputs.index(this) + 1);
if (nextInput) {
nextInput.focus();
}
}
});
")
})
}
# Run the application
shinyApp(ui = ui, server = server)
The javascript is from here and included in shiny with shinyjs
.

Community
- 1
- 1

Tonio Liebrand
- 17,189
- 4
- 39
- 59