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

Make updateSelectizeInput() work with labels again #2248

Merged
merged 4 commits into from Nov 15, 2018
Merged

Conversation

wch
Copy link
Collaborator

@wch wch commented Nov 6, 2018

This fixes #2245.

Test application:

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 (selectizetInput)", choices=c("A", "B", "C"))
)

server <- function(input, output,session) {
  observeEvent(input$update,{
    updateSelectInput(session, "select", label="New label (selectInput)", choices = c("X", "Y", "Z"))
    updateSelectizeInput(session, "selectize", label="New label (selectizeInput)", choices = c("X", "Y", "Z"))
  })
}

shinyApp(ui = ui, server = server)

@jcheng5 jcheng5 added this to the 1.2.1 milestone Nov 15, 2018
if (typeof(selectize) !== 'undefined') {
selectize.setValue(value);
} else $(el).val(value);
if (this._is_selectize(el)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional is backward

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😬

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);
Copy link
Member

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

// 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) {
Copy link
Member

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;

@wch
Copy link
Collaborator Author

wch commented Nov 15, 2018

I've made the changes, and have a new test app which exercises the setValue() code path.

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)

@wch wch merged commit 6a373b5 into master Nov 15, 2018
@wch wch deleted the fix-selectize-label branch November 15, 2018 23:04
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

Successfully merging this pull request may close these issues.

updateSelectizeInput label is broken in shiny 1.2
2 participants