Skip to content

Selectize input doesn't remove selected class from un-selected options #3839

Closed

Description

@gadenbuie

Here's a small reprex app that demonstrates that previously selected options in a selectize input retain the selected class. Ideally, the output would match only the currently selected option, but it accumulates options as select them.

library(shiny)

ui <- fluidPage(
  selectInput("letter", "Letter", LETTERS),
  verbatimTextOutput("selected"),
  tags$script(HTML("
function check_selected(id) {
  const selected = $('#' + id + ' + .selectize-control .selectize-dropdown .selected').text();
  Shiny.setInputValue('list_selected', selected);
}
Shiny.addCustomMessageHandler('check-selected', check_selected)
check_selected('letter')
"
  ))
)

server <- function(input, output, session) {
  observe({
    input$letter
    session$sendCustomMessage('check-selected', 'letter')
  })
  
  output$selected <- renderPrint({
    input$list_selected
  })
}

shinyApp(ui, server)
Kapture.2023-06-12.at.16.50.48.mp4

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions