Hello,
I have a need to cancel a checkbox check if the user has reached a limit. Unfortunately, simply calling preventDefault isn't working when the checked item is a parent. So I whipped up a little jQuery to handle this for me --
I can see this works fine. If I put a breakpoint at the end, the treeview looks perfect. However, it appears that some other internal kendo event is firing after and resetting the items to a checked state. As I understood things, calling the set method should have been updating the underlying data for the treeview, so I didn't expect my changes to be overwritten... What am I missing?
Thanks,
Phil
I have a need to cancel a checkbox check if the user has reached a limit. Unfortunately, simply calling preventDefault isn't working when the checked item is a parent. So I whipped up a little jQuery to handle this for me --
$("#treeview").on("click", ":checkbox", function (e) { var treeView = $("#treeview").data("kendoTreeView"); origChecked = listChecked; listChecked = []; checkedNodeIds(treeView.dataSource.view(), listChecked); if (searchLimited && listChecked.length > searchLimit) { var newChecked = $(listChecked).not(origChecked).get(); $.each(newChecked, function (index, value) { var item = treeView.dataSource.get(value); item.set("checked", false); }); e.preventDefault(); listChecked = origChecked; }});// function that gathers IDs of checked nodesfunction checkedNodeIds(nodes, checkedNodes) { for (var i = 0; i < nodes.length; i++) { if (nodes[i].checked) { if (nodes[i].id != "0") { checkedNodes.push(nodes[i].id); } } if (nodes[i].hasChildren) { checkedNodeIds(nodes[i].children.view(), checkedNodes); } }}I can see this works fine. If I put a breakpoint at the end, the treeview looks perfect. However, it appears that some other internal kendo event is firing after and resetting the items to a checked state. As I understood things, calling the set method should have been updating the underlying data for the treeview, so I didn't expect my changes to be overwritten... What am I missing?
Thanks,
Phil