Hi,
I am trying to have selection tags so that if someone clicks a tag, it only shows results for that tag without having to deselect it when changing to another tag.
Example: for my music site, you can see when you switch between kids, tense, lively etc you have to deselect them to make them go away: https://payment37.wixsite.com/candytunes
What I want it to do is so that when you click “Kids” it just shows kids music, then if they click “Tense” it just shows tense and they don’t have to unclick kids etc . If anyone has any suggestions I’d be very grateful I think it might be possible with using the onChange function for the selection tags element but not good with the code.
I’ve pretty much done everything else to make this design work which I’m pleased about but this is the only thing left I need to sort out lol!
code:
import wixData from ‘wix-data’ ;
const collectionName = ‘Tracks’ ;
const fieldToFilterByInCollection = ‘trackName’ ;
$w.onReady( function () {
setRepeatedItemsInRepeater();
loadDataToRepeater();
$w( '#tag' ).onChange((event) => {
const selectedTags = $w( ‘#tag’ ).value;
loadDataToRepeater(selectedTags);
})
});
function loadDataToRepeater(selectedCategories = ) {
let dataQuery = wixData.query(collectionName);
if (selectedCategories.length > 0 ) {
dataQuery = dataQuery.hasSome(fieldToFilterByInCollection, selectedCategories);
}
dataQuery
.find()
.then(results => {
const itemsReadyForRepeater = results.items;
$w( ‘#repeater2’ ).data = itemsReadyForRepeater;
const isRepeaterEmpty = itemsReadyForRepeater.length === 0
if (isRepeaterEmpty) {
$w( ‘#noResultsFound’ ).show();
} else {
$w( ‘#noResultsFound’ ).hide();
}
})
}
function setRepeatedItemsInRepeater() {
$w( '#repeater2' ).onItemReady(($item, itemData) => {
$item( '#trackname' ).text =itemData.title;
$item( '#audioplayer149' ).tooltip = itemData.audio;
})
}