Load items from tags field from filtered dataset - without having to input those items in the selection tag element

This is to complete the following closed post: New Feature: Selection Tags from Eyal Michael Cohen


Collection fields:


The Dataset is not connected to the element:


Code:

import wixData from "wix-data";
import { session } from 'wix-storage';

var sectionVAR;
var subSectionVAR;
var filterVAR;
var keyWordsArray = [];

$w.onReady(async function () {

    $w("#tagsKeyWords").options = [];

 // get variable1 sent from other page
    sectionVAR = session.getItem("section");
 // get variable2 sent from other page
    subSectionVAR = session.getItem("subSection");

 if (sectionVAR === "type") {
        filterVAR = wixData.filter()
            .eq("type", subSectionVAR)
            .ne("archived", true);
    }

 if (sectionVAR === "integration") {
        filterVAR = wixData.filter()
            .eq("integration", subSectionVAR)
            .ne("archived", true);
    }

 if (sectionVAR === "source") {
        filterVAR = wixData.filter()
            .eq("source", subSectionVAR)
            .ne("archived", true);
    }

 if (sectionVAR === "company") {
        filterVAR = wixData.filter()
            .eq("company", subSectionVAR)
            .ne("archived", true);
    }

 // filter my dataset, thus filtering the repeater
 await $w("#datatsetDevKnow").setFilter(filterVAR);

 await $w("#listRepeater").onItemReady(($item, itemData, index) => {
 // all keyWordsTags from this item
 let itemKeyWords = itemData.keyWordsTags;

 if (itemKeyWords.length > 0) {
            $w("#boxKeyWords").expand();
 // loop through the itemKeyWords
 for (var i = 0; i < itemKeyWords.length; i++) {
 var itemKeyWord = itemKeyWords[i];
 // add each itemKeyWord to keyWordsArray
                keyWordsArray.push(itemKeyWord);
            }
        } else {
            $w("#boxKeyWords").collapse();
        }
    });

 // sort array alphabetically
    keyWordsArray.sort();
 // remove duplicates
 let uniqueKeywords = getUniqueTags(keyWordsArray);
 // build into options for selectionTags
 let finalKeyWords = buildOptionsTags(uniqueKeywords);
 // display options in element
    $w("#tagsKeyWords").options = finalKeyWords;
});

function getUniqueTags(array) {
 return [...new Set(array)]
}

function buildOptionsTags(uniqueList) {
 return uniqueList.map((curr) => {
 return { label: curr.toString(), value: curr };
    });
}

Results:

1 Like