10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-11-09 07:33:52 +01:00
QUESTDB_website/static/js/nestedCheckbox.js

38 lines
1.3 KiB
JavaScript
Raw Normal View History

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
}
}
2020-05-19 10:30:28 +02:00
nestedCheckbox_refreshMainValidity(checkbox)
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
}
2020-05-19 10:30:28 +02:00
nestedCheckbox_refreshMainValidity(checkbox)
}
function nestedCheckbox_refreshMainValidity(checkbox) {
if (checkbox.data("onerequired") && !(checkbox.is(":checked") || checkbox.is(":indeterminate")) ) {
checkbox.first().each(function() {
this.setCustomValidity("Please check at least one of the checkboxes below")
})
}
else {
checkbox.first().each(function() {
this.setCustomValidity("")
})
}
2020-01-04 18:07:19 +01:00
}