Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast clicks can cause issues with bsModal #128

Open
tylerlittlefield opened this issue Oct 5, 2020 · 0 comments
Open

Fast clicks can cause issues with bsModal #128

tylerlittlefield opened this issue Oct 5, 2020 · 0 comments

Comments

@tylerlittlefield
Copy link

tylerlittlefield commented Oct 5, 2020

I have an app that uses bsModal with two actionButton's for canceling and confirming. The actionButtons are observed and toggleModal takes care of the rest. The problem is that if a user double clicks, or clicks multiple times fast enough, we get "stuck" in the modal.

library(shiny)
library(shinyBS)

ui <- fluidPage(
  actionButton("go", "open modal"),
  bsModal("modal", "modal", NULL, actionButton("close", "close modal"))
)

server <- function(input, output, session) {
  observeEvent(input$go, {
    toggleModal(session, "modal", "open")
  })
  
  observeEvent(input$close, { # <------------- click this close button multiple times, fast
    toggleModal(session, "modal", "close")
  })
}

shinyApp(ui, server)

After some testing, it seems that we can resolve this by disabling the button on click:

library(shiny)
library(shinyBS)

ui <- fluidPage(
  shinyjs::useShinyjs(),
  actionButton("go", "open modal"),
  bsModal("modal", "modal", NULL, actionButton("close", "close modal", onclick="this.disabled=true;this.value='Submitting...'; this.form.submit();"))
)

server <- function(input, output, session) {
  
  observeEvent(input$go, {
    shinyjs::enable("close")
    toggleModal(session, "modal", "open")
  })
  
  observeEvent(input$close, {
    toggleModal(session, "modal", "close")
  })
}

shinyApp(ui, server)

src: https://stackoverflow.com/a/27471389/7362046

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant