HI,
Can any one help me finish this code?
I have a data set called $w(“#trainingDataset”) its a database full of different exercises.
I want to filter the data set using group check boxes. i have it working on the below code with one issue i have to check at least 1 box in each group there are 4 groups that obviously contain multiple check boxes.
pushPullcheckboxgroup
exerciseTypecheckboxgroup
equipmentCheckboxgroup
muscleGroupcheckboxgroup
you can see the check box groups in the photo.
I want it so that it filters each time i click a check box no matter if that’s 1 box or multiple boxes.
for example if i click pull it filters the dropdown to show only the pull exercises.
here’s the code that works but only if at least 1 box is checked in each group.
//Exercise filter
export function FilterByExercise(){
let ppl = ;
let exerciseType = ;
let equipmentType = ;
let muscleGroup = ;
// Get the indexes of all the checkboxes checked in that group
let selectedppl = $w(“#pushPullcheckboxgroup”).selectedIndices;
let selectedexerciseType = $w(“#exerciseTypecheckboxgroup”).selectedIndices;
let selectedequipmentType = $w(“#equipmentCheckboxgroup”).selectedIndices;
let selectedmuscleGroup = $w(“#muscleGroupcheckboxgroup”).selectedIndices;
// Now, loop through the checked items and add each field to the array
if (selectedppl.length > 0){
for ( var i = 0; i < selectedppl.length; i++) {
ppl.push($w(‘#pushPullcheckboxgroup’).options[selectedppl[i]].value);
}
}
if (selectedexerciseType.length > 0){
for ( var i2 = 0; i2 < selectedexerciseType.length; i2++) {
exerciseType.push($w(‘#exerciseTypecheckboxgroup’).options[selectedexerciseType[i2]].value);
}
}
if (selectedequipmentType.length > 0){
for ( var i3 = 0; i3 < selectedequipmentType.length; i3++) {
equipmentType.push($w(‘#equipmentCheckboxgroup’).options[selectedequipmentType[i3]].value);
}
}
if (selectedmuscleGroup.length > 0){
for ( var i4 = 0; i4 < selectedmuscleGroup.length; i4++) {
muscleGroup.push($w(‘#muscleGroupcheckboxgroup’).options[selectedmuscleGroup[i4]].value);
}
}
$w("#trainingDataset").setFilter(wixData.filter()
.hasSome("ppl", ppl)
.hasSome("exerciseType", exerciseType)
.hasSome("equipmentType", equipmentType)
.hasSome("muscleGroup", muscleGroup)
);
}
export function pushPullcheckboxgroup_change(event) {
FilterByExercise();
}
export function exerciseTypecheckboxgroup_change(event) {
FilterByExercise();
}
export function equipmentCheckboxgroup_change(event) {
FilterByExercise();
}
export function muscleGroupcheckboxgroup_change(event) {
FilterByExercise();
}