Skip to content

Commit

Permalink
fixed bug selected arg with ID
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Sep 22, 2022
1 parent d4a0fc9 commit 903e5b9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: shinytreeview
Title: Tree View for 'shiny' Applications
Version: 0.1.0
Version: 0.1.1
Authors@R:
c(person(given = "Victor",
family = "Perrier",
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# shinytreeview 0.1.1

## Bug fixes

* Fixed `selected = ` argument when using an ID to select initial value(s).


# shinytreeview 0.1.0

* New function `updateTreeview()` to update label and selected value from the server.
Expand Down
2 changes: 2 additions & 0 deletions R/input-treeview.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ make_tree <- function(data, levels, selected = NULL, levels_id = NULL, ...) {
stopifnot(
"levels and levels_id must be of same length" = length(levels) == length(levels_id)
)
if (!all(levels_id %in% names(data)))
stop("All levels_id must be valid variables in data", call. = FALSE)
mapply(
SIMPLIFY = FALSE,
USE.NAMES = FALSE,
Expand Down
2 changes: 1 addition & 1 deletion inst/packer/treeview.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions srcjs/inputs/treeview.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ $.extend(treeviewInputBinding, {
exactMatch: true,
revealResults: false
});
if (selected.length < 1) {
selected = tree.findNodes("^" + data.selected[i] + "$", "id");
}
tree.selectNode(selected);
var parents = tree.getParents(selected);
var maxLevel = Math.max.apply(
Expand Down Expand Up @@ -132,6 +135,9 @@ $.extend(treeviewInputBinding, {
exactMatch: true,
revealResults: false
});
if (selected.length < 1) {
selected = tree.findNodes("^" + options.selected[i] + "$", "id");
}
tree.selectNode(selected);
var parents = tree.getParents(selected);
var maxLevel = Math.max.apply(
Expand Down Expand Up @@ -210,6 +216,9 @@ $.extend(treecheckInputBinding, {
exactMatch: true,
revealResults: false
});
if (selected.length < 1) {
selected = tree.findNodes("^" + data.selected[i] + "$", "id");
}
tree.toggleNodeChecked(selected);
}
tree.search("", {
Expand Down Expand Up @@ -274,6 +283,9 @@ $.extend(treecheckInputBinding, {
exactMatch: true,
revealResults: false
});
if (selected.length < 1) {
selected = tree.findNodes("^" + options.selected[i] + "$", "id");
}
tree.toggleNodeChecked(selected);
}
tree.search("", {
Expand Down

0 comments on commit 903e5b9

Please sign in to comment.