简体   繁体   中英

jQuery Mask Plugin with r shiny textInput

Is there a way to do something like jQuery Mask Plugin with a R-Shiny textInput ?

I'm trying to make a textInput display a mask as I'm typing.

Exemple: I want to type 11111111111 and, as I type, the textInput value displays 111.111.111-11.

Any ideas?

Do you mean something like this? Or something more fancy? ;)

library(shiny)
library(stringi)

ui <- fluidPage(
  textInput("textin", "Enter Text"),
  textOutput("text")
)

server <- function(input, output) {
  output$text <- renderText({
    textout <- input$textin
    textout <- paste(stri_sub(textout, 1, 3),".",
                     stri_sub(textout, 4, 6), ".",
                     stri_sub(textout, 7, 9), "-",
                     stri_sub(textout, 10, 12), ".",
                     stri_sub(textout, 13, 14), ".")

    print(textout)
  })
}

shinyApp(ui, server)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM