#repeater #distinct
Hey,
I am writing code for a custom search bar that also has a suggested search. So when a user starts typing a repeater checks for data from a data set and displays results. Some of the data is repeated and I would like for it to show only one.
I have tried using distinct(); but from my understanding that only works for dropdown menus.
repeaterResults is where the final result is shown
searchBar is a text box where the user can type
dataset1 is where the data is being filtered from
repeaterSearch is where the suggestion is being shown.
import wixData from 'wix-data';
$w.onReady(function () {});
export function searchBar_keyPress(event)
{
$w("#repeaterResults").data = [];
setTimeout(() => {
if ($w("#searchBar").value.length >= 1)
{
$w("#dataset1").setFilter(wixData.filter().startsWith("area", $w("#searchBar").value))
.then(() => {
count();
})
}
else {
$w("#repeaterSearch").collapse();
}
},500)
}
function count () {
let total = $w("#repeaterSearch").data.length;
if (total > 0) {
$w("#repeaterSearch").expand();
} else {
$w("#repeaterSearch").collapse();
}
}
export function repeaterSearch_itemReady($item, itemData, index)
{
$item("#area").onClick(() => {
//$w("#repeaterResults").data = [];
$w("#searchBar").value = $item("#area").text;
$w("#repeaterSearch").collapse();
$w("#repeaterSearch").data = [];
})
}