This is a new issue that has appeared despite no changes in site code.
(i.e. the same code has worked properly for over a year)
The issue is intermittent: reloading the page can sometimes result in successful display of the option array and sometimes not.
This dropdown option array is populated by code based on a collection query.
The dropdown list is assembled correctly and can be printed to the console (which always shows the correct list).
Yet the dropdown does not reliably display the list.
Has anyone else seen this? Fixed it? How?
Where is your used code? Can’t see any code.
//This code populates the option list for the dropdown $w(‘#dropdownMember’)
//It starts by calling a function to build an array (artistProfiles) containing the list.
//This function is a Promise and the .then guarantees that the code does not proceed before the result is returned.
//This array is 100% always correct even when the dropdown malfunctions
dropdownMembersCreateList(artistProfiles)
.then ((result) => {
//To check: print returned array to console - this array is 100% always correct
console.log("In catalog edit-manager-dropdownMember options: result: ",result);
//Load the options into the dropdown
$w(‘#dropdownMember’).options = result;
//Just to check again: transfer the options list to a new variable and print it to the console - this array is 100% always correct
let resultTest = $w(‘#dropdownMember’).options;
console.log("In catalog edit-manager-dropdownMember options: $w(‘#dropdownMember’).options: ", resultTest);
//At this point the dropdown should isplay the options list - sometimes it does and others it does not…
});
Looking at your code, i just can say, this code never ever has been runing before.
Either you have collected all the parts somewhere from the web, or you have had engaged a real bad developer/programmer to solve your problem.
How ever, your code should look like this example one…
import wixData from 'wix-data';
$w.onReady(function () {myFunction()});
function myFunction (parameter) {
let myQuery = wixData.query("Test-DB")
.find()
.then ((result) => {
console.log("RESULTS: ", result)
console.log("RESULTS-ITEMS ", result.items)
let myDropDownOptions = []
for (var i = 0; i < result.length; i++) {
myDropDownOptions.push(
{"label": result.items[i].title, "value": result.items[i].title},
)
}
$w('#dropdownMember').options = myDropDownOptions
});
}
Of course to be able to run this CODE and fill the dropdown, you have to create a database, where you store all your items, which should later appear in the DropDown.
Here an example of how your DB should look like to test the functionality of this little code-snipet…
I apologize, I did not show you all the code.
I believe it has all the elements of your example.
I create the dropdown options list in a separate function and call it as a Promise, otherwise it is the same.
It still fails intermittantly.
$w.onReady( function () {
wixData.query( “Directory” )
.contains( “relation” , “Artist” )
.eq ( “status” , “ACTIVE” )
.ascending( “nameLast” , “nameFirst” )
.find()
.then((artists) => {
artistProfiles = artists.items;
dropdownMembersCreateList(artistProfiles)
.then ((result) => {
memberOptions = result;
$w( '#dropdownMember' ).options = memberOptions;
});
})
. **catch** ( (err) => {
console.log( "In catalog edit. Error = " ,err);
}) //End Artist query results
})
function dropdownMembersCreateList(itemData) {
return new Promise ((resolve, reject) => {
let memberSelectList = [{label: “Me” , value:currentUserData.artistId}];
let artistItem;
itemData.forEach( function (artist) {
artistItem = { value: artist._id, label: artist.fullName};
memberSelectList.push(artistItem);
})
resolve (memberSelectList);
})
}