top of page
Forum Posts
Pav Slyzyak
May 28, 2020
In Coding with Velo
Hi, can someone help? The idea is to use a repeater to give an options to a dropdown through a collapsible box (so it creates a filter by checkbox). The code itself seems okay but not quite sure, Idea came from: https://www.wix.com/corvid/forum/community-discussion/solved-filter-dataset-from-group-check-boxes-and-update-a-dropdown-box-with-that-filter Heres the code that i've used on the page: import wixData from 'wix-data';
//Exercise filter
export function FilterByDrink() {
let alcohol = [];
let mixer = [];
let garnish = [];
// Get the indexes of all the checkboxes checked in that group
let selectedalcohol = $w("#AlcoholCheckboxGroup").selectedIndices;
let selectedmixer = $w("#MixerCheckboxGroup").selectedIndices;
let selectedgarnish = $w("#GarnishCheckboxGroup").selectedIndices;
let filter = wixData.filter();
// Now, loop through the checked items and add each field to the array and apply filter
if (selectedalcohol.length > 0) {
for (var i = 0; i < selectedalcohol.length; i++) {
alcohol.push($w('#AlcoholCheckboxGroup').options[selectedalcohol[i]].value);
}
}
if (alcohol.length > 0) {
filter = filter.hasSome("AlcoholTags", alcohol);
}
if (selectedmixer.length > 0) {
for (var i2 = 0; i2 < selectedmixer.length; i2++) {
mixer.push($w('#MixerCheckboxGroup').options[selectedmixer[i2]].value);
}
}
if (mixer.length > 0) {
filter = filter.hasSome("MixerTags", mixer);
}
if (selectedgarnish.length > 0) {
for (var i3 = 0; i3 < selectedgarnish.length; i3++) {
garnish.push($w('#GarnishCheckboxGroup').options[selectedgarnish[i3]].value);
}
}
if (garnish.length > 0) {
filter = filter.hasSome("GarnishTags", garnish);
}
$w("#dataset1").setFilter(filter)
.then(() => {
console.log("count after", $w("#dataset1").getTotalCount());
$w("#numberOfdrinksavailable").value = "Number of drinks available" + " " + $w("#dataset1").getTotalCount()
})
.catch((err) => {
console.log(err);
});
}
// Filetr each time you click a check box in a group
export function AlcoholCheckboxGroup_change(event) {
//Add your code for this event here:
FilterByDrink();
}
export function MixerCheckboxGroup_change(event) {
//Add your code for this event here:
FilterByDrink();
}
export function GarnishCheckboxGroup_change(event) {
//Add your code for this event here:
FilterByDrink();
}
export function AlcoholTitleBox_click_1(event) {
//Add your code for this event here:
if ($w('#AlcoholBox').collapsed) {
$w('#AlcoholBox').expand();
} else
$w('#AlcoholBox').collapse();
}
export function MixerTitleBox_click(event) {
//Add your code for this event here:
if ($w('#MixerBox').collapsed) {
$w('#MixerBox').expand();
} else
$w('#MixerBox').collapse();
}
export function GarnishTitleBox_click(event) {
//Add your code for this event here:
if ($w('#GarnishBox').collapsed) {
$w('#GarnishBox').expand();
} else
$w('#GarnishBox').collapse();
} If someone can help, would be really appreciated. #checkbox #checkboxfilter #userinput #filter #dropdown #tickbox #
0
3
327
Pav Slyzyak
More actions
bottom of page