Hi, I created a filter to search for professional information based on some conditions but it’s not working. This is the code:
// For full API documentation, including code examples, visit Velo API Reference - Wix.com
import wixData from ‘wix-data’;
export function search_click(event, items) {
$w("#dataset1").setFilter(wixData.filter()
.contains("serviceType", $w("#servicetype").value)
.contains("profession", $w("#profession").value)
.contains("location", $w("#location").value))
.then(results => {
console.log("Dataset is now filtered");
$w("#repeater1").data = results.items;
}). catch (error => {
console.log(error);
})
$w("#repeater1").expand();
}
This is the site url: https://elliosedgeservice.wixsite.com/mysite
If the Repeater is connected to the Dataset, then you should not set the Repeater’s .data property to the results of the filter. However, the .then() function would be the correct place to .expand() the Repeater:
import wixData from 'wix-data';
export function search_click(event, items) {
$w("#dataset1").setFilter(wixData.filter()
.contains("serviceType", $w("#servicetype").value)
.contains("profession", $w("#profession").value)
.contains("location", $w("#location").value))
.then(results => {
console.log("Dataset is now filtered");
// don't need this: $w("#repeater1").data = results.items;
$w("#repeater1").expand();
}).catch(error => {
console.log(error);
})
}
If you are still having problems with this, on what page are you having the problem?
Thanks, I’ve done it but I still have the same issue. It’s the professional page.
Since you are doing a filter based on a reference field , you need to use the ID of the referenced item as a String. So, you need to populate the dropdown box with the label as the type string, and the value as the referenced item’s ID.
Do you mean the element ID because the referenced collection contains several items with each item having their own ID and I’m trying to filter from all the contents of the collection. Could you please explain better as I’m a novice in coding. Thanks
I mean the ID of the item in the referenced collection:
Also, it is suggested that for reference fields .eq() should be used instead of .contains() . There is additional information in the API documentation .