mirror of
https://github.com/rstudio/shiny.git
synced 2026-04-07 03:00:20 -04:00
Fix custom selectize rendering
Fixes #2192. Two problems here: 1. It's not documented but apparently we supported data frames for choices in updateSelectInput/updateSelectizeInput (it doesn't appear to work correctly for selectInput/selectizeInput though). This was used in 023-optgroup-server as well as by the user who reported #2172. 2. The example in 023-optgroup-server was also counting on the default value of optgroupLabelField, which (starting post-Shiny v1.1) was being set to a new default of "group". That now won't happen unless optgroupField is also blank. I'm less confident about the ramifications of this change. The selectize docs with the relevant bits are here: https://github.com/selectize/selectize.js/blob/master/docs/usage.md#data_searching
This commit is contained in:
@@ -654,7 +654,14 @@ updateSelectizeInput <- function(session, inputId, label = NULL, choices = NULL,
|
||||
}
|
||||
}
|
||||
# convert choices to a data frame so it returns [{label: , value: , group: },...]
|
||||
choices <- if (is.atomic(choices) || noOptGroup) {
|
||||
choices <- if (is.data.frame(choices)) {
|
||||
# jcheng 2018/09/25: I don't think we ever said data frames were OK to pass
|
||||
# to updateSelectInput, but one of the example apps does this and at least
|
||||
# one user noticed when we broke it.
|
||||
# https://github.com/rstudio/shiny/issues/2172
|
||||
# https://github.com/rstudio/shiny/issues/2192
|
||||
as.data.frame(choices, stringsAsFactors = FALSE)
|
||||
} else if (is.atomic(choices) || noOptGroup) {
|
||||
# fast path for vectors and flat lists
|
||||
if (is.list(choices)) {
|
||||
choices <- unlist(choices)
|
||||
|
||||
@@ -5401,14 +5401,25 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
||||
var $el = $(el);
|
||||
var config = $el.parent().find('script[data-for="' + $escape(el.id) + '"]');
|
||||
if (config.length === 0) return undefined;
|
||||
|
||||
var options = $.extend({
|
||||
labelField: 'label',
|
||||
valueField: 'value',
|
||||
searchField: ['label'],
|
||||
optgroupField: 'group',
|
||||
optgroupLabelField: 'group',
|
||||
optgroupValueField: 'group'
|
||||
searchField: ['label']
|
||||
}, JSON.parse(config.html()));
|
||||
|
||||
if (!options.optgroupField) {
|
||||
// We set the defaults for optgroupField separately from the other
|
||||
// defaults, because if optgroupField was explicitly provided then we
|
||||
// don't want to default optgroupLabelField and optgroupValueField.
|
||||
// https://github.com/rstudio/shiny/issues/2192
|
||||
options = $.extend({
|
||||
optgroupField: 'group',
|
||||
optgroupLabelField: 'group',
|
||||
optgroupValueField: 'group'
|
||||
}, options);
|
||||
}
|
||||
|
||||
// selectize created from selectInput()
|
||||
if (typeof config.data('nonempty') !== 'undefined') {
|
||||
el.nonempty = true;
|
||||
|
||||
File diff suppressed because one or more lines are too long
2
inst/www/shared/shiny.min.js
vendored
2
inst/www/shared/shiny.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -138,14 +138,25 @@ $.extend(selectInputBinding, {
|
||||
var $el = $(el);
|
||||
var config = $el.parent().find('script[data-for="' + $escape(el.id) + '"]');
|
||||
if (config.length === 0) return undefined;
|
||||
|
||||
var options = $.extend({
|
||||
labelField: 'label',
|
||||
valueField: 'value',
|
||||
searchField: ['label'],
|
||||
optgroupField: 'group',
|
||||
optgroupLabelField: 'group',
|
||||
optgroupValueField: 'group'
|
||||
searchField: ['label']
|
||||
}, JSON.parse(config.html()));
|
||||
|
||||
if (!options.optgroupField) {
|
||||
// We set the defaults for optgroupField separately from the other
|
||||
// defaults, because if optgroupField was explicitly provided then we
|
||||
// don't want to default optgroupLabelField and optgroupValueField.
|
||||
// https://github.com/rstudio/shiny/issues/2192
|
||||
options = $.extend({
|
||||
optgroupField: 'group',
|
||||
optgroupLabelField: 'group',
|
||||
optgroupValueField: 'group'
|
||||
}, options);
|
||||
}
|
||||
|
||||
// selectize created from selectInput()
|
||||
if (typeof(config.data('nonempty')) !== 'undefined') {
|
||||
el.nonempty = true;
|
||||
|
||||
Reference in New Issue
Block a user