Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_checked doesn't return checked until something has been selected #121

Open
chrismiddleton opened this issue Sep 16, 2023 · 3 comments
Open

Comments

@chrismiddleton
Copy link

First, thanks for developing this wrapper for jsTree, it's very useful.

In my app, I'm trying to show a tree where any item in the tree can be checked, and separately, an item in the tree can be selected to open it up and reveal its contents. As a result, I have these options set:

 checkbox = TRUE,
 tie_selection = FALSE,

However, when checking an item, the get_checked method still returns an empty list(). I believe this is due to this line here: https://github.com/shinyTree/shinyTree/blob/master/R/init.R#L91

where it has

if (json$state$selected != FALSE) {
    attr(ret, "stchecked") <- json$state$checked
}

But this will only update the stchecked attr if item is selected, not checked. I would think it should read:

if (json$state$checked != FALSE) {
    attr(ret, "stchecked") <- json$state$checked
}

I can submit a PR if this looks correct to you.

@chrismiddleton
Copy link
Author

chrismiddleton commented Sep 16, 2023

I did some more testing locally and got this to work, but there was another change required in shinyTree.js to make it work:

if (el.dataset.stCheckbox == "TRUE" && el.dataset.stTieSelection == "FALSE") {
  $(el).on("check_node.jstree", function(e) {
    callback();
  });
  $(el).on("uncheck_node.jstree", function(e) {
    callback();
  });
  $(el).on("check_all.jstree", function(e) {
    callback();
  });
  $(el).on("uncheck_all.jstree", function(e) {
    callback();
  });
}

I will publish a PR for you to review soon.

@chrismiddleton
Copy link
Author

PR added here: #122

@bellma-lilly
Copy link
Contributor

@chrismiddleton Thanks for identifying this issue. I think you are part of the way there with the fix.

First a question about this line:

if (el.dataset.stCheckbox == "TRUE" && el.dataset.stTieSelection == "FALSE") {

Does this need to be conditional? What happens if the callbacks are always called?

Second, if tie_selection is false, stchecked should be set when an item is selected.

Could you address these points?

You may want to update example 04 with separate checked and selected sections and explain how the app should act when tie_selection is True or False (and maybe include the whole_node option).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants