Hello,
I am completely new to coding and have followed several tutorials, but can’t seem to figure out what I’m doing wrong. I am creating a website with multiple recipes on it. I need to allow visitors to be able to filter through the All Recipes page. I would like them to do this by Category.
I have a Recipe database and a Dropdown List database containing the Category options. The Categories field in the Recipe database is a reference field connected to the Dropdown List database.
At this point everything works except the actual filtering. The page title changes with selection, and the clear action button works as well. However, the repeater itself does not change when I make different category selections on the dropdown.
This is on a dynamic page. I have attempted to do the same on a regular page, but it did not work at all.
Any and all help is greatly appreciated. Let me know if any additional information is needed from me.
-
Dropdown List dataset = #ListCategory
-
Recipe dataset = #dataset1
-
Recipe dynamic dataset = #recipeDataset
-
Dropdown = #dropdown1
-
Page Title = #pageTitleText
This is my current code:
import wixData from ‘wix-data’ ;
$w.onReady( function () {
});
let selectedCategories = “” ;
export function dropdown1_change(event) {
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:
wixData.query( “DropdownList” )
.eq( “title” , $w( “#dropdown1” ).value)
.find()
.then( (results) => {
let firstItem = results.items[ 0 ]; //First Item in results
selectedCategories = firstItem._Id;
wixData.query( "Recipes" )
.eq( "categories" , selectedCategories)
.find()
.then( (results) => {
$w( "#repeater1" ).data = results.items;
$w( "#pageTitleText" ).text = "Recipes - " + $w( "#dropdown1" ).value;
})
. **catch** ( (err) => {
let errorMsg=err;
});
});
}
export function clearButton_click(event, $w) {
// Reload all items when clear button clicked
wixData.query ( “Recipes” )
.find()
.then( (results) => {
$w( “#repeater1” ).data = results.items;
$w( “#pageTitleText” ).text = “Recipes - All” ;
})
. catch ( (err) => {
let errorMsg = err;
});
}