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
Make updateSelectizeInput() work with labels again #2248
Conversation
srcjs/input_binding_select.js
Outdated
if (typeof(selectize) !== 'undefined') { | ||
selectize.setValue(value); | ||
} else $(el).val(value); | ||
if (this._is_selectize(el)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This conditional is backward
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😬
srcjs/input_binding_select.js
Outdated
if (data.hasOwnProperty('label')) | ||
$(el).parent().parent().find('label[for="' + $escape(el.id) + '"]').text(data.label); | ||
if (data.hasOwnProperty('label')) { | ||
let label_name = $escape(el.id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better variable for label_name
would be escaped_id
srcjs/input_binding_select.js
Outdated
// Return true if it's a selectize input, false if it's a regular select input. | ||
_is_selectize: function(el) { | ||
var config = $(el).parent().find('script[data-for="' + $escape(el.id) + '"]'); | ||
if (config.length === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified to return config.length > 0;
d05679d
to
775d528
Compare
I've made the changes, and have a new test app which exercises the library(shiny)
ui <- fluidPage(
actionButton('update','Update selectize inputs'),
selectInput("select", "Original label (selectInput)", choices=c("A", "B", "C"), selectize = FALSE),
selectizeInput("selectize", "Original label (selectizeInput)", choices=c("A", "B", "C"))
)
server <- function(input, output,session) {
observeEvent(input$update,{
# Set the choices and selected value in two separate steps to test the
# setValue code path.
updateSelectInput(session, "select", label="New label (selectInput)",
choices = c("D", "E", "F"))
updateSelectInput(session, "select", selected = "E")
updateSelectizeInput(session, "selectize", label="New label (selectizeInput)",
choices = c("X", "Y", "Z"))
updateSelectInput(session, "selectize", selected = "Y")
})
}
shinyApp(ui = ui, server = server) |
This fixes #2245.
Test application: