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

If two different categories have sub-categories with the same name then both get checked. #19

Closed
purak24 opened this issue Feb 8, 2017 · 3 comments
Labels

Comments

@purak24
Copy link

purak24 commented Feb 8, 2017

I have a category A with sub categories B, C and D and another category E with sub categories F, G and B. Now when I check sub category B under category A, the sub category B under category E also gets checked!

@jakezatecky
Copy link
Owner

Yes, this is because the checked property only records the node values. If a node value is duplicated by any other node, then you will experience this behavior. The tree therefore requires that each node have a unique value. You can solve this be merely concatenating the parent nodes to the child nodes (e.g. A-B and E-B).

I suppose we could validate all supplied nodes for value uniqueness and throw an error if a duplicate is detected, providing more developer-friendly debugging. Might impact performance, so it probably makes sense to have this as a property that can be disabled (e.g. validateUniqueness).

A more exotic option could also exist, where the node value are automatically concatenated with their parent values, but that would change the resulting tree's values.

@purak24
Copy link
Author

purak24 commented Feb 9, 2017

I don't think validating nodes for value uniqueness will be a good idea. I can think of many use cases where leaf nodes may have same values but under different categories.

What I ended up doing is pushing the key ({index}-{node.name}) instead of name in the checked array. That works!

@jakezatecky
Copy link
Owner

Closing since this is pretty easy for the developer to adjust to.

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

No branches or pull requests

2 participants