Copied Site; Dropdown code not loading dropdown anymore

Hey all!

I have a site with code that loads a dropdown (list of employees) and it has worked perfectly for the past year. I copied my site for a friend to use and the employees dropdown no longer loads the list of employees, but it is the same exact code.

There are two parts to my code: the page code and a backend utilitiesModule.jsw file code (both sets of code below).

Does anyone have an idea of why the dropdown code works on my site but is not working on the copied site?

Page code:

function loadDropdown() {
wixData.query(‘Employees’)
.limit(1000)
.find()
.then( async res => {
employees = res.items;
employees = employees.sort((a, b) => a.name.localeCompare(b.name));
let options = ;
options.push(…res.items.map(dropdown => {
return {
“label”: dropdown.name,
“value”: dropdown._id
};
}));
options = options.sort((a, b) => a.label.localeCompare(b.label));
$w(‘#dropdownEmployee’).options = options;

let evaluatorEmail = await wixUsers.currentUser.getEmail();

  evaluator = employees.find(o => o.email === evaluatorEmail); 

  $w("#dropdownEvaluator").options = [{ 

“label”: evaluator.name,
“value”: evaluator._id
}];
$w(“#dropdownEvaluator”).selectedIndex = 0;

  $w("#inputEvaluatorRole").value = evaluator.role; 

//})

}) 
. **catch** (err => { 
  console.log("Fatal Error. Contact Administrator"); 
}); 

}

utilitiesModule.jsw Backend file code:

// Filename: backend/utilitiesModule.jsw (web modules need to have a .jsw extension)
import wixData from ‘wix-data’;

export function populateDropdown(collectionName, valueField) {
let allItems = ;
return wixData.query(collectionName)
.ascending(“name”)
.find()
.then((results) => {
if (results.totalCount > 0) {
let items = results.items;
items.forEach((item) => {
let oneItem = {
label: item.name,
value: item[valueField].toString()
}
allItems.push(oneItem);
})
return allItems;
}
return null ;

}) 

}

Copied sites only copy page elements and code on page, it won’t or sometimes doesn’t always copy anything like event handlers for example that you’ve added through properties panel.

So you need to go through the copied site and make sure that everything is still connected as it should be like event handlers, datasets, links and so on.

Sometimes it is quicker just to redo it again instead of just copying and pasting up.

Hmm, that doesn’t sound right. I duplicate sites all the time and have never encountered a problem with event handlers, or anything else for that matter.

@jmeas, I see that you’re using wix-users. Maybe that’s the cause of the problem, since it would depend on the site’s “users”.

Do either of you have cases where this can be replicated? If this is in fact a problem I’d like to pass this on up the food chain.

Hey @yisrael-wix , I reviewed the entire duplicated site and everything was copied perfectly including event handlers, etc. This must be an issue with wix-users like you mentioned. Are you able to look at my site and see where the cause of this issue is? What do you need from me?

@measurescfa Each site has its own users. Maybe the new site just doesn’t have users.

@yisrael-wix The dropdowns populate from my Employees database. The new site has all employees entered into the Employees database, so that’s confusing. Would there be an issue with there being blank items in the database?

@yisrael-wix Update: it’s all working now. All I did was remove the blank items from the database and the dropdowns are good to go. Thanks for your help!

2 Likes

@measurescfa Way to go! I was just going to ask you to post the link to your site. Glad you got it worked out!

BTW - how did the blank items get in there? Were they in the original site? Curious why the original site worked but the duplicate didn’t. Oh well - can’t argue with success.

1 Like

Don’t worry about it Yisrael, this was done when I copied something many moons ago and I was probably immediately thinking back to the good old days!

It definitely wasn’t anytime recent, so if you’ve not had any issues yourself when you’ve duplicated sites recently, then it must have been something that got fixed months or years ago.

Now if only we could duplicate a drink that easily…:blush:

@yisrael-wix When my friend added items to her Employee database, she added new items and cleared the old ones, leaving over a 100 blank items. I’m not sure why those were causing the dropdowns to not load, but once I removed the blank items from her database, the dropdowns loaded perfectly.

1 Like

@givemeawhisky Don’t worry? Don’t worry you say! :worried:I lose sleep over these kind of things. :exploding_head: I toss and turn all night. :fearful: I have nightmares, the most hideous nightmares: the fridge has no beer, my son ordering wheat beer in a bar, my bottles of single malt being replaced with sloe gin and rock and rye .

2 Likes

@yisrael-wix That is no nightmare, that is just sheer torture to the soul :face_with_symbols_over_mouth:

1 Like