Dropdowns with Hooks values

Hi,
I need to display concatenated value in my dropdown.
I have created hook like this:

export function Fields_afterGet(item, context) {

item.displayWizardName = item.fieldName + “(” + item.cefName + “)”;

return item;
}
And now i want my dropdown to display a list of displayWizardName values. How do i populate it in dropdown?

1 Like

Did you ever solve this? i need to do the same

nope :frowning:

This sounds pretty easy.
https://www.wix.com/corvid/reference/$w.Dropdown.html#options

I mean something like:

(some get query).....
.then((results) => {
    let items = results.items;
    let options = [];
    items.forEach((e) => {
        options.push({"label": e.displayWizardName, "value": e.displayWizardName });
    })
    $w("#dropdown1").options = options;
}) 

@chana

I just done it try this.

obviously replace all my element and database names with your own

import wixData from ‘wix-data’;

//On clickj event on the drop down button
export function longNamedropdown_click(event) {
fullNamedropdown()
}

//Fullname calculated field in the MemberProfile5 database, this is the code to create a unique drop down list.
function fullNamedropdown() {
wixData.query(“MemberProfile5”)
.limit(1000)
.ascending(“fullName”)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w(“#longNamedropdown”).options = buildOptions(uniqueTitles);
});
//Maps unique items from “fullName” column which is a hook calculated field
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.fullName);
return [… new Set(titlesOnly)];
}
//Builds the drop down list from unique values using current labels and titles
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}