CODE FOR 3 DROPDOWNS:  Remove duplicates and populate the options without datasets

THE CODE

import wixData from 'wix-data';

 

$w.onReady(function () {

    uniqueDropDown1();

});

function uniqueDropDown1 (){

    wixData.query("collection")

        .limit(1000)

      .find()

      .then(results => {

           const uniqueTitles = getUniqueTitles(results.items);

           $w("#dropdownName1").options = buildOptions(uniqueTitles);

      });

  function getUniqueTitles(items) {

        const titlesOnly = items.map(item => item.fieldkey);

     return [...new Set(titlesOnly)];

    }

    function buildOptions(uniqueList) {

        return uniqueList.map(curr => {

            return {label:curr, value:curr};

        });

    }

}

 

export function genre_change(event, $w) {

uniqueDropDown2();

$w("#dropdownName2").enable();

}

 

function uniqueDropDown2 (){

    wixData.query("collection")

        .contains("fieldkey", $w("#dropdownName1").value)

        .limit(1000)

      .find()

      .then(results => {

           const uniqueTitles = getUniqueTitles(results.items);

           $w("#dropdownName2").options = buildOptions(uniqueTitles);

      });

  function getUniqueTitles(items) {

        const titlesOnly = items.map(item => item.fieldkey);

     return [...new Set(titlesOnly)];

    }

    function buildOptions(uniqueList) {

        return uniqueList.map(curr => {

            return {label:curr, value:curr};

        });

    }

}

 

export function subcategory_change(event, $w) {

uniqueDropDown3();

$w("#dropdownName3").enable();

}

 

function uniqueDropDown3 (){

    wixData.query("collection")

        .contains("fieldkey", $w("#dropdownName2").value)

        .limit(1000)

      .find()

      .then(results => {

           const uniqueTitles = getUniqueTitles(results.items);

           $w("#dropdownName3").options = buildOptions(uniqueTitles);

      });

  function getUniqueTitles(items) {

        const titlesOnly = items.map(item => item.fieldkey);

     return [...new Set(titlesOnly)];

    }

    function buildOptions(uniqueList) {

        return uniqueList.map(curr => {

            return {label:curr, value:curr};

        });

    }

}

CODE FOR 2 DROPDOWNS:  Remove duplicates and populate options without datasets.

THE CODE

import wixData from 'wix-data';

 

$w.onReady(function () {

    uniqueDropDown1();

});

function uniqueDropDown1 (){

    wixData.query("collection")

        .limit(1000)

      .find()

      .then(results => {

           const uniqueTitles = getUniqueTitles(results.items);

           $w("#dropdownName1").options = buildOptions(uniqueTitles);

      });

  function getUniqueTitles(items) {

        const titlesOnly = items.map(item => item.fieldkey);

     return [...new Set(titlesOnly)];

    }

    function buildOptions(uniqueList) {

        return uniqueList.map(curr => {

            return {label:curr, value:curr};

        });

    }

}

 

export function genre_change(event, $w) {

uniqueDropDown2();

$w("#dropdownName2").enable();

}

 

function uniqueDropDown2 (){

    wixData.query("collection")

        .contains("fieldkey", $w("#dropdownName1").value)

        .limit(1000)

      .find()

      .then(results => {

           const uniqueTitles = getUniqueTitles(results.items);

           $w("#dropdownName2").options = buildOptions(uniqueTitles);

      });

  function getUniqueTitles(items) {

        const titlesOnly = items.map(item => item.fieldkey);

     return [...new Set(titlesOnly)];

    }

    function buildOptions(uniqueList) {

        return uniqueList.map(curr => {

            return {label:curr, value:curr};

        });

    }

}

CODE FOR 2 DROPDOWNS:  Filtering by using datasets that don't contain duplicates

THE CODE

import wixData from 'wix-data';

 

$w.onReady(function () {

});

 

export function locationStateDropDown_change(event, $w) {

$w("#dropdownName2").enable();

locationCityFilter();

}

 

function locationCityFilter (){

$w("#dataset").setFilter( wixData.filter()

.eq("fieldkey", $w("#dropdown").value)

);

}

This website was created by Code Queen LLC