Skip to content

Commit

Permalink
renamed 'tieSelection' -> 'checkWithText' and 'ID_selected_tree' -> '…
Browse files Browse the repository at this point in the history
…ID_checked_tree'.
  • Loading branch information
stla committed Oct 20, 2023
1 parent 4094fda commit 96a97be
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 18 deletions.
8 changes: 6 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# jsTreeR 2.4.0 (2023-11-??)

- New option `tieSelection`. It is a `TRUE`/`FALSE` option about the behavior
of the checkboxes: it controls whether the checkboxes must be selected when
- New option `checkWithText`. It is a `TRUE`/`FALSE` option about the behavior
of the checkboxes: it controls whether the checkboxes must be (un)checked when
clicking on the text of a node.

- The Shiny input value `ID_selected_tree` (see `?jstree-shiny`) has been
renamed to `ID_checked_tree`. If you set `checkWithText` to `FALSE`, then
you *must* use this input value to get the selected nodes.


# jsTreeR 2.3.3 (2023-10-10)

Expand Down
5 changes: 4 additions & 1 deletion R/jstree-shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
#' except that it provides the paths to the selected nodes instead of only
#' the values of their text field, and you have a fifth Shiny \code{input}
#' value if you have set \code{checkboxes=TRUE} in the \code{\link{jstree}}
#' command: \code{input[["ID_selected_tree"]]}, which is like
#' command: \code{input[["ID_checked_tree"]]}, which is like
#' \code{input[["ID_selected"]]} except that it preserves the hierarchy, in
#' other words it provides the selected nodes with their parent(s).
#' If you have set \code{checkboxes=TRUE} and \code{checkWithText=FALSE} in
#' the \code{\link{jstree}} command, then \code{input[["ID_checked_tree"]]}
#' is the only way to get the selected nodes.
#'
#' @name jstree-shiny
#'
Expand Down
8 changes: 4 additions & 4 deletions R/jstree.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#' selected leaves
#' @param checkboxes logical, whether to enable checkboxes next to each node;
#' this makes easier the selection of multiple nodes
#' @param tieSelection logical, whether the checkboxes must be selected when
#' @param checkWithText logical, whether the checkboxes must be selected when
#' clicking on the text of a node
#' @param search either a logical value, whether to enable the search
#' functionality with default options, or a named list of options for the
Expand Down Expand Up @@ -375,7 +375,7 @@ jstree <- function(
nodes, elementId = NULL,
selectLeavesOnly = FALSE,
checkboxes = FALSE,
tieSelection = TRUE,
checkWithText = TRUE,
search = FALSE, searchtime = 250,
dragAndDrop = FALSE, dnd = NULL,
multiple = TRUE,
Expand Down Expand Up @@ -406,7 +406,7 @@ jstree <- function(
stopifnot(is.null(elementId) || isString(elementId))
stopifnot(isBoolean(selectLeavesOnly))
stopifnot(isBoolean(checkboxes))
stopifnot(isBoolean(tieSelection))
stopifnot(isBoolean(checkWithText))
stopifnot(isBoolean(search) || isNamedList(search))
stopifnot(isBoolean(dragAndDrop))
stopifnot(is.null(dnd) || isNamedList(dnd))
Expand All @@ -425,7 +425,7 @@ jstree <- function(
data = nodes,
selectLeavesOnly = selectLeavesOnly,
checkbox = checkboxes,
tieSelection = ifelse(checkboxes, tieSelection, TRUE),
checkWithText = ifelse(checkboxes, checkWithText, TRUE),
search = search,
searchtime = searchtime,
dragAndDrop = dragAndDrop,
Expand Down
4 changes: 2 additions & 2 deletions inst/essais/essai_tieSelection.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ server <- function(input, output, session){
jstree(
nodes,
checkboxes = TRUE,
tieSelection = FALSE,
checkWithText = FALSE,
checkCallback = TRUE
)
)
})

observe({
print(input$myTree_selected_tree)
print(input$myTree_checked_tree)
print("____________________")
})
}
Expand Down
12 changes: 6 additions & 6 deletions inst/htmlwidgets/jstreer.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function setShinyValueSelectedNodes(instance, leavesOnly, checkboxes) {
);
if(checkboxes){
Shiny.setInputValue(
instance.element.attr("id") + "_selected_tree:jsTreeR.list",
instance.element.attr("id") + "_checked_tree:jsTreeR.list",
filterChecked(instance, ["text", "data", "type"])
);
}
Expand Down Expand Up @@ -171,10 +171,10 @@ HTMLWidgets.widget({

if (x.checkbox)
options.checkbox = {
keep_selected_style: !x.tieSelection,
keep_selected_style: !x.checkWithText,
cascade_to_disabled: false,
tie_selection: x.tieSelection,
whole_node: x.tieSelection
tie_selection: x.checkWithText,
whole_node: x.checkWithText
//three_state: false,
//cascade: "up+undetermined"
};
Expand Down Expand Up @@ -209,7 +209,7 @@ HTMLWidgets.widget({
/* $el.on("click", ".jstree-anchor", function(evt) {
alert("CLICK");
console.log(evt);
if(!x.tieSelection && !($(evt.target).hasClass("jstree-checkbox"))) {
if(!x.checkWithText && !($(evt.target).hasClass("jstree-checkbox"))) {
evt.stopPropagation();
}
}); */
Expand Down Expand Up @@ -285,7 +285,7 @@ HTMLWidgets.widget({
} // modif 9/10/2023
});

if(!x.tieSelection) {
if(!x.checkWithText) {
$el.on("check_node.jstree", function(e, data) {
$el.jstree(true).select_node(data.node);
if(inShiny) {
Expand Down
5 changes: 4 additions & 1 deletion man/jstree-shiny.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/jstree.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 96a97be

Please sign in to comment.