Open stewerner opened 1 month ago
Hello,
Thank you for your message. I've just checked my JavaScript code and then I've seen that I commented out one line in the handler of the changed.jstree
event so that input$mytree_full
is not updated. Unfortunately I don't remember why I commented out this line.
Hi, that's strange. The changed event seems to be pretty straight forward. How are the manual selections captured?
There's nothing strange.
A selection triggers the select_node.jstree
event. And in inst/htmlwidgets/jstreer.js
I have a handler for this event:
$el.on("select_node.jstree", function(e, data) {
if(inShiny) {
setShinyValue(data.instance, checkboxes);
} // modif 9/10/2023
});
My function setShinyValue
updates input$mytree_full
.
But as I said, I commented out the call to this function in my handler of the changed.jstree
event:
$el.on("changed.jstree", function(e, data) {
if(inShiny) {
// Shiny.setInputValue(
// id, getNodesWithChildren(data.instance.get_json())
// );
setShinyValueSelectedNodes(data.instance, leavesOnly, checkboxes);
if(checkboxes) {
setShinyValueCheckedNodes(data.instance, leavesOnly);
}
//setShinyValue(data.new_instance); // modif 9/10/2023
}
});
I don't remember why. Perhaps because this function was called multiple times in some circumstances.
Strange, as I would have expected select_all
to trigger a more general event like select_node
.
And it seems changed.jstree
should be the way to go:
https://groups.google.com/g/jstree/c/3LLvol8nx1A/m/xvoTIonFticJ
However, select_all also triggers select_all.jstree. Same logic for deselect. Maybe this would be an option.
It seems changed.jstree
was commented out after I filed this issue which you fixed with this commit.
Maybe it would have been sufficient to just add the after_open
and after_close
events?
I just left a PR which seems to fix this.
The original line //setShinyValue(data.new_instance); // modif 9/10/2023
didn't work but
setShinyValue(data.instance);
did.
(an alternative still would be listening on select_all.jstree
/ deselect_all.jstree
)
I was trying to implement a button to select / deselect all nodes. However, it seems this change is not reflected in the shiny input:
Example: