diff --git a/inst/essais/on_rename.R b/inst/essais/on_rename.R new file mode 100644 index 0000000..6dbe66f --- /dev/null +++ b/inst/essais/on_rename.R @@ -0,0 +1,87 @@ +library(jsTreeR) +library(shiny) +library(jsonlite) + +nodes <- list( + list( + text = "Branch 1", + state = list( + opened = TRUE, + disabled = FALSE, + selected = FALSE, + undetermined = TRUE + ), + type = "parent", + children = list( + list( + text = "Leaf A", + state = list( + opened = TRUE, + disabled = FALSE, + selected = FALSE, + checked = FALSE, + undetermined = FALSE + ), + type = "child" + ), + list( + text = "Leaf B", + state = list( + opened = TRUE, + disabled = FALSE, + selected = FALSE, + checked = FALSE, + undetermined = FALSE + ), + type = "child" + ), + list( + text = "Leaf C", + state = list( + opened = TRUE, + disabled = FALSE, + selected = FALSE, + checked = TRUE, + undetermined = FALSE + ), + type = "child" + ), + list( + text = "Leaf D", + state = list( + opened = TRUE, + disabled = FALSE, + selected = FALSE, + checked = TRUE, + undetermined = FALSE + ), + type = "child" + ) + ) + ), + list( + text = "Branch 2", + type = "parent", + state = list( + opened = TRUE, + disabled = FALSE, + selected = FALSE, + checked = TRUE, + undetermined = FALSE + ) + ) +) + +ui <- fluidPage(jstreeOutput("mytree"), verbatimTextOutput("mytree_full")) + +server <- function(input, output, session) { + output[["mytree"]] <- renderJstree({ + jstree(nodes, contextMenu = TRUE, checkboxes = TRUE, checkWithText = FALSE) + }) + + output$mytree_full <- renderPrint({toJSON(input$mytree_full, pretty = TRUE)}) +} + + + +shinyApp(ui, server) diff --git a/inst/htmlwidgets/jstreer.js b/inst/htmlwidgets/jstreer.js index 33469bd..3f2a152 100644 --- a/inst/htmlwidgets/jstreer.js +++ b/inst/htmlwidgets/jstreer.js @@ -402,7 +402,7 @@ HTMLWidgets.widget({ $el.on("rename_node.jstree", function(e, data) { if(inShiny) { var instance = data.instance; - var parentPath = instance.get_path(data.node.parent); + var parentPath = instance.get_path(data.node.parent) || []; var oldPath = parentPath.concat(data.old); var newPath = parentPath.concat(data.text); Shiny.setInputValue("jsTreeRenamed:jsTreeR.move", {