dreamRs / shinyWidgets

shinyWidgets : Extend widgets available in shiny
https://dreamrs.github.io/shinyWidgets/
GNU General Public License v3.0
830 stars 153 forks source link

autonumericInput minimumValue prevents typing large multi-digit numbers #463

Open CloudStriderGames opened 2 years ago

CloudStriderGames commented 2 years ago

I guess this is just a side effect of autonumeric input, but maybe there is some workaround that I need to know.

If I set the minimumValue of an autonumericInput to "5" (for example) and I want to enter "11" into the window it obviously stops me from doing so, since the first digit I would enter would be to small. This means typing number like this is really annoying. I would basically have to enter "511" and than delete the 5 afterwards.

Is there a different solution, or maybe a way of clamping the entered value to minimumValue/maximumValue after you are done entering the number?

pvictor commented 2 years ago

Apparently there's no workaround. You can see {this issue](https://github.com/autoNumeric/autoNumeric/issues/560) regarding this problem.

An alternative can be to add a visual alert in the UI then use req server side:

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  theme = bslib::bs_theme(version = 4),
  h1("Autonumeric Inputs"),
  br(),
  autonumericInput(
    inputId = "id1",
    label = "Default Input",
    value = 6, 
    styleRules = list(
      ranges = list(
        list(min = -1e9, max = 5, class = "is-invalid"),
        list(min = 5, max = 1e9, class = "is-valid")
      )
    )
  ),
  verbatimTextOutput("res1")
)

server <- function(input, output, session) {
  output$res1 <- renderPrint({
    val <- req(input$id1, input$id1 > 5)
    val
  })
}

shinyApp(ui, server)

Note that classes is-invalid and is-valid are specific to Bootstrap 4, so output depends on what framework you use, but you can also use your own CSS.