Good day to all,
Basically I have a dynamic page that is linked to two databases that previews supplements in a repeater. I am trying to add a dropdown filter with a clear button so that visitors can filter by brand of supplement. When a selection from the dropdown menu is chosen, the Title of page changes to that which the visitor has selected, and it obviously filters the repeater to show only selected Brand. I did not save this work as I am continuously publishing and still experimenting with this and so far it hasn’t worked.
This is the code I am using, I hope you can tell me what I am doing wrong:
//My clear button’s ID is clearButton and has an onClick event called clearButton_click
//My drop down’s ID is selection1 and has an onChange event called selection1_change
//My dynamic page title’s ID is text21.
//I have two databases connected to the dynamic page:
1)SupplementBrandCategory 2)Amino-BCAA
//My dropdown list is connected to SupplementBrandCategory database, labels and values
connected to Title
//My repeater is connected to Amino-BCAA database
//Inside database of Amino-BCAA i added a reference field that references the database SupplementBrandCategory. Its field value is called brandOfSupplement, and its field name is called brand of supplement
//My repeater’s ID is repeater1
Still the code is not working !
import wixData from 'wix-data';
$w.onReady(function () {
});
let selectedCategory = "";
export function selection1_change(event, $w) {
wixData.query("SupplementBrandCategory")
.eq("title",$w("#selection1").value)
.find()
.then( (results) => {
let firstItem = results.item[0];
selectedCategory = firstItem._id;
wixData.query("Amino-BCAA")
.eq("brandOfSupplement",selectedCategory)
.find()
.then( (results) => {
$w("#repeater1").data = results.items;
$w("#text21").text = "POST WORKOUTS - " + $w("#selection1").value;
} )
.catch( (err) => {
let errorMsg =err;
} );
});
}
export function clearButton_click(event, $w) {
wixData.query("Amino-BCAA")
.find()
.then( (results) => {
$w("#repeater1").data = results.items;
$w("#text21").text = "POST WORKOUTS - ALL";
} )
.catch( (err) => {
let errorMsg = err;
} );
}
I will be extremely thankful to anyone who can tell me what I am doing wrong here!!!