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:
Joe Cheng
2018-09-25 12:56:02 -07:00
parent e7c4656e8f
commit 49a346334b
6 changed files with 41 additions and 12 deletions

View File

@@ -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;