Hello guys, I have a selection menu working with tags. I would like that when I select a new voice, it will automatically deselect the previous one and then update the content. Now it just adds the new products even if the tag is not the one selected. Can anyone help me?
The code that I already have is this:
import wixData from 'wix-data';
const databaseName = 'Portainnesti';
const databaseField = 'tipo';
$w.onReady(function () {
$w('#selectionTags1').onChange((event) => {
const selectedTag = $w('#selectionTags1').value;
addItemstoRepeater(selectedTag);
})
});
function addItemstoRepeater(selectedOption = []) {
let dataQuery = wixData.query(databaseName);
if (selectedOption.length > 0) {
dataQuery = dataQuery.hasSome(databaseField, selectedOption);
}
dataQuery
.find()
.then(results => {
const filtereditemsReady = results.items;
$w('#repeater1').data = filtereditemsReady;
})
}
$w.onReady(function () {
$w('#selectionTags1').onChange(()=>{
let VALUE = $w('#selectionTags1').value
let LENGTH = VALUE.length
console.log(LENGTH)
for (var i = 0; i < LENGTH-1; i++) {
if(LENGTH>1) {
VALUE.shift()
}
else{}
}
console.log(VALUE)
setTimeout(()=>{
$w('#selectionTags1').value = []
$w('#selectionTags1').value = VALUE
},1)
})
});
Thanks :)
All you need to do is:
$w('#tags').onChange(event => { $w('#tags').value = [$w('#tags').value.reverse()[0]]; })
Are you searching for a "Single-Tag-Selection" ???
If so, take a look onto this one...
The included EXAMPLE will not work anymore (since i have deleted some stuff on my site) but you can read the post, which will show you how to achieve your wished functionality.