Question:
I’ve created a search function in velo, so that websites-guests can seach by topic. I tried to embedd the possibility to search for more than one field, but this doesn’t work. The goal is, that in one search field, the user can search for whatever he wants. as example:
if the collection is an adress-list, I want to have the possibility, that the user can put either the name, the city, the street or the country. not depending on which of them he is putting in, the searchbar should find the appropriate entries. how to do this?
This is the current code:
import wixData from "wix-data";
$w('#suche').onClick((event) => {
wixData
.query("Verbandsmitglieder")
.contains("title", $w("#suchfeld").value)
.find()
.then((results) => {
if (results.totalCount > 0) {
$w("#suchresultate").data = results.items;
}
})
.catch((error) => {
console.error(error);
});
$w("#suchresultate").onItemReady(($item, itemData, index) => {
$item("#title").text = itemData.title;
$item("#strasse").text = itemData.strasse;
$item("#ort").text = itemData.ort;
$item("#webseite").link = itemData.webseite;
});
});
I tried with multiple contains:
import wixData from "wix-data";
$w('#suche').onClick((event) => {
wixData
.query("Verbandsmitglieder")
.contains("title", $w("#suchfeld").value)
.contains("ort", $w("#suchfeld").value)
.contains("kanton", $w("#suchfeld").value)
.find()
.then((results) => {
if (results.totalCount > 0) {
$w("#suchresultate").data = results.items;
}
})
.catch((error) => {
console.error(error);
});
$w("#suchresultate").onItemReady(($item, itemData, index) => {
$item("#title").text = itemData.title;
$item("#strasse").text = itemData.strasse;
$item("#ort").text = itemData.ort;
$item("#webseite").link = itemData.webseite;
});
});
But it doens’t work. the searchbar works only for the last contains entry.
Product:
Wix Editor
What are you trying to achieve:
See question