Checkbox for single item only

2,548 views
Skip to first unread message

Chu

unread,
Jan 26, 2011, 5:19:25 PM1/26/11
to jsTree
I'm using the checkbox plugin but I need to change the way it works.
My tree can go up to N levels deep and will end as a leaf. I need to
give the user the option of selecting an item, but one item only. The
current checkbox plugin has these items that I need to get around:

1- When a parent item is checked and then opened up, all children are
selected. I need only the parent to be selected and never the
children.
2- When a child is selected, the parent gets the "3rd state" -- which
is undesirable. I simply want the child to be selected.

Basically, I would like the tree to behave in a manner consistent with
only being able to select a single item throughout the entire tree. Is
this possible to accomplish?

Thanks in advance for suggestions.

mvwd

unread,
Jan 28, 2011, 10:55:24 AM1/28/11
to jsTree
First: set in jsTree's-config the checkboxes to use only two states
(use newest commit of jsTree!):

checkbox : { "two_state" : true }

Second: setup the 'change_state'-Event and check if a node is already
checked. If so: cancel the second check:

.bind("change_state.jstree", function(e, data){
if(data.inst.get_checked().length>1){
data.inst.uncheck_node(data.rslt[0]);
}
})

In this case i will UNDO the check, because i haven't found a solution
to really CANCEL the check/event -> but the result is the same... ;-)

Markus.

Rety Matos

unread,
Nov 27, 2017, 8:29:47 PM11/27/17
to jsTree
How can I made this in 3.3.4 version?

Rety Matos

unread,
Nov 27, 2017, 8:37:28 PM11/27/17
to jsTree
My bad...

.on('check_node.jstree uncheck_node.jstree', function(e, data){
if(data.instance.get_checked().length>1){
data.instance.uncheck_node(data.selected[0]);
}
})

Thanks!
Reply all
Reply to author
Forward
0 new messages