EN VI

Javascript - How can I add an onBlur event to a selectizeInput?

2024-03-11 23:30:07
Javascript - How can I add an onBlur event to a selectizeInput

I would like to trigger an event when the user leaves a selectize-Input. However for selectizeInput it does not work and for textInput it only fires once:

library(shiny)

ui <- fluidPage(
  selectizeInput("si", label="letters", choices = letters),
  tags$script(HTML(
    '
      $("#si").on("blur", function() {
        console.log("boawigjawegaosdgi");
      })
      '
  )),
  textInput("ti", label = "ti"),
  tags$script(HTML(
    '
      $("#ti").on("blur", function() {
        console.log("boawisdgi");
      })
      '
  )),
)

server <- function(input, output, session) {
  
}

shinyApp(ui, server)

What could I change so it works?

Solution:

It works normally for the textInput For the selectizeInput, you have to use the onBlur option:

  selectizeInput(
    "si", label="letters", choices = letters,
    options = list(
      onBlur = I('function() {console.log("boawigjawegaosdgi")}')
    )
  )
Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login