Dhanush Bala
Dhanush Bala

Reputation: 1132

check only one checkbox from treeview

$("#grouptree").treeview({
            animated: "fast",
        collapsed: true,
        unique: true,
        persist: "cookie",
        toggle: function() {
            window.console && console.log("%o was toggled", this);
        }
    });

above code is my treeview code , Each one checkbox has class='treecheck' , allow user to check only one checkbox from treeview

Upvotes: 0

Views: 1022

Answers (1)

Ehsan Sajjad
Ehsan Sajjad

Reputation: 62488

you have to write change event on class treecheck and whenever one is changed uncheck other with this class name.

You can do this way using not():

HTML:

<input type="checkbox" class="treecheck"/>
<input type="checkbox" class="treecheck"/>
<input type="checkbox" class="treecheck"/>
<input type="checkbox" class="treecheck"/>
<input type="checkbox" class="treecheck"/>

JQUERY:

$('.treecheck').on('change', function() {
    $('.treecheck').not(this).prop('checked', false);  
});

FIDDLE

FIDDLE DEMO

Upvotes: 1

Related Questions