2020-01-04 18:07:19 +01:00
|
|
|
function nestedCheckbox_change(e) {
|
2020-05-19 10:17:55 +02:00
|
|
|
checkbox = $(e.target);
|
2020-01-04 18:07:19 +01:00
|
|
|
//Apply children
|
2020-05-19 10:17:55 +02:00
|
|
|
if (!checkbox.is(":indeterminate")) {
|
|
|
|
var ul = checkbox.parent("li").next("ul")
|
2020-01-04 18:07:19 +01:00
|
|
|
if (ul.length != 0) {
|
2020-05-19 10:17:55 +02:00
|
|
|
ul.children("li").children("input[type=checkbox]").prop("checked", checkbox.is(":checked"));
|
2020-01-04 18:07:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//Apply parent
|
2020-05-19 10:17:55 +02:00
|
|
|
var ul=checkbox.parent("li").parent("ul")
|
2020-01-04 18:07:19 +01:00
|
|
|
var checkbox=$(ul).prev("li").children("input[type=checkbox]")
|
|
|
|
checkboxes=ul.children("li").children("input[type=checkbox]")
|
|
|
|
var checkeds=Array.from(checkboxes).map(el=>el.checked)
|
2020-01-09 11:12:46 +01:00
|
|
|
var scheckeds=Array.from(new Set(checkeds))
|
|
|
|
if (scheckeds.length>1) {
|
|
|
|
checkbox.prop("checked",false);
|
2020-01-04 18:07:19 +01:00
|
|
|
checkbox.prop("indeterminate",true);
|
|
|
|
}
|
|
|
|
else{
|
2020-01-09 11:12:46 +01:00
|
|
|
checkbox.prop("indeterminate",false);
|
|
|
|
checkbox.prop("checked",scheckeds[0]);
|
2020-01-04 18:07:19 +01:00
|
|
|
}
|
|
|
|
}
|