Hi, i was wondering whether its possible to code such that one of the tags in my selection tag is already chosen when my page loads. Currently, I have 3 tags where only 1 can be chosen any single time but I don't want all of my gallery to be shown when a user enters the page.
top of page
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
bottom of page
import wixData from 'wix-data'; let dbField = "title"; //<---- change here the DATABASE-FIELD you want to use $w.onReady(function() { let filter=wixData.filter(); let mySelectecIndex =[0]; //<--- sets the selectionTag'S index to the first value $w("#mySelectedTags").selectedIndices=mySelectecIndex; //<--- $w('#dataset1').onReady(()=> { $w('#selectionTags1').onChange(()=>{ let selectedTags = $w('#selectionTags1').value; //<-- sets new value //function for ONE-SELECTION-ONLY..... for(var i=0; i<selectedTags.length-1; i++){ if(selectedTags.length>1){ selectedTags.shift(); } if(i===selectedTags.length-1){ $w('#selectionTags1').value=[]; $w('#selectionTags1').value=selectedTags; filter=filter.hasSome(dbField, selectedTags[0]; $w('#dataset1').setFilter(filter); } }); }); });
Hi thanks for the reply, I got the code from the links you put above.
I think you misunderstood what i wanted to achieve.
I wanted the page to load in a way where not everything in the dataset is shown but only those filtered by the selection tag that was already selected when the page loads. Thats why i tried using the code you provided above however my dataset did not filter according to the chosen selected tag.
let mySelectecIndex =[0];$w("#mySelectedTags").selectedIndices=mySelectecIndex;
With...
https://www.wix.com/velo/reference/$w/selectiontags/selectedindices
... you can define selected indices of your SELECTION-TAG-ELEMENT.
Chose the values inside of the element-array, which you want to be selected on start.
--->
let mySelectecIndex = [0]; $w("#mySelectedTags").selectedIndices=mySelectecIndex;