Skip to content

Commit

Permalink
bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Jul 21, 2017
1 parent 802c318 commit e5af9e6
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: shinyWidgets
Title: Custom Inputs Widgets for Shiny
Version: 0.3.1.110
Version: 0.3.2
Authors@R: c(
person("Victor", "Perrier", email = "[email protected]", role = c("aut", "cre")),
person("Fanny", "Meyer", email = "[email protected]", role = c("aut")),
Expand Down
15 changes: 14 additions & 1 deletion R/input-multi.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#' }
multiInput <- function(inputId, label, choices = NULL, selected = NULL, options = NULL, width = NULL, choiceNames = NULL, choiceValues = NULL) {
selectTag <- tags$select(
id = inputId, multiple = "multiple",
id = inputId, multiple = "multiple", class= "multijs",
makeChoices(choices = choices, choiceNames = choiceNames,
choiceValues = choiceValues, selected = selected)
)
Expand Down Expand Up @@ -96,3 +96,16 @@ makeChoices <- function(choices = NULL, choiceNames = NULL, choiceValues = NULL,



updateMultiInput <- function (session, inputId, label = NULL, selected = NULL, choices = NULL) {
choices <- if (!is.null(choices))
choicesWithNames(choices)
if (!is.null(selected))
selected <- validateSelected(selected, choices, inputId)
options <- if (!is.null(choices))
paste(capture.output(makeChoices(choices, selected)), collapse = "\n")
message <- dropNulls(list(label = label, options = options, value = selected))
print(message)
session$sendInputMessage(inputId, message)
}


65 changes: 65 additions & 0 deletions inst/www/multi/multi-bindings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// multi input binding
var exportsMulti = window.Shiny = window.Shiny || {};
var $escapeMulti = exportsMulti.$escape = function(val) {
return val.replace(/([!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~])/g, '\\$1');
};

var multiInputBinding = new Shiny.InputBinding();
$.extend(multiInputBinding, {
find: function(scope) {
return $(scope).find('.multijs');
},
getId: function(el) {
return el.id;
},
getValue: function(el) {
return $(el).val();
},
setValue: function setValue(el, value) {
$(el).val(value).change();
},
getState: function(el) {
// Store options in an array of objects, each with with value and label
var options = new Array(el.length);
for (var i = 0; i < el.length; i++) {
options[i] = { value: el[i].value,
label: el[i].label };
}

return {
label: $(el).parent().find('label[for="' + $escapeMulti(el.id) + '"]').text(),
value: this.getValue(el),
options: options
};
},
receiveMessage: function(el, data) {
var $el = $(el);

// This will replace all the options
if (data.hasOwnProperty('options')) {
// Clear existing options and add each new one
$el.empty().append(data.options);
//$(el).trigger( 'change' );
}

if (data.hasOwnProperty('value')) {
this.setValue(el, data.value);
}

if (data.hasOwnProperty('label')) $(el).parent().parent().find('label[for="' + $escapeMulti(el.id) + '"]').text(data.label);

//$(el.id).trigger( 'change' );
$(el).trigger('change');
},
subscribe: function(el, callback) {
$(el).on('change', function (event) {
//$(el.id).trigger( 'change' );
//$(el).trigger('change');
callback();
});
},
unsubscribe: function(el) {
$(el).off('.multiInputBinding');
}
});
Shiny.inputBindings.register(multiInputBinding, 'shiny.multiInput');
Loading

0 comments on commit e5af9e6

Please sign in to comment.