Utilizing checkboxes to gather values and store them in an array for dataset filtering purposes.
The objectives are as follows:
Show child filters when parent category is selected.
Unselect all children if parent is unselected (otherwise they will remain hidden but still selected)
Display active filters
Remove active filter on click (also uncheck corresponding checkbox programmatically).
Clear all filters and uncheck all checkboxes.
Present code provided below, see attached fiddle for more information.
$scope.IsChecked = false;
$scope.ActiveFilters = [];
$scope.clearFilters = function() {
$scope.ActiveFilters = [];
};
$scope.ModifyFilter = function (IsChecked, Filter) {
console.log(IsChecked);
if (IsChecked) {
$scope.ActiveFilters.push(Filter);
}
else {
var indexz = $scope.ActiveFilters.indexOf(Filter);
$scope.ActiveFilters.splice(indexz, 1);
}
};
For a partially functional demo, check out the Fiddle here
-- EDIT --
Extra clarification: If a checkbox value is removed from the 'Active Filters' section by clicking on its name at the bottom of the fiddle, it does not result in unchecking the checkbox. The same issue occurs when using 'Clear Filters'.