Dropdown not loading options

Hi

I’m having some problems with dynamically loaded options of a dropdown. I’m calling a 3rd party API and getting some options. I map these options to a value / label object. Sometimes, just rarely, the options are loaded, so the mapping is correct. I’m suspecting that the dropdowns aren’t infact ready.

$w.onReady(function () {
	getStations().then(payload => {
		let stations = mapStationsToDropdown(payload.Result.Stations);
		
		// List is complete, and looking good				
		console.log(stations);
		
		$w("#dropOffLocation").options = $w("#pickUpLocation).options = stations;
		
		// List is complete, and looking good. UI just isn't updated....
		console.log($w("#dropOffLocation").options ) 
	})
	
	...
});

Any suggestions to what I’m doing wrong?

Hi jeppe,

This line looks a bit of.

$w ( “#dropOffLocation” ). options = $w ( "#pickUpLocation ). options = stations ;

You add pickUpLocations to dropOffLocations, and also trying to add stations to pickUpLocations…

I’m not sure what you are tring to do,
But if dropofLocations and pickUpLocations would be the same you only have to add stations to both of them.

Like this:
$w ( “#dropOffLocation” ). options = stations ;
$w ( "#pickUpLocation ). options = stations ;

Hi Kristoff
Thanks for your answer. That line is just syntax sugar for assigning stations to both dropdowns in a one-liner. I’ve also tried your suggestion without any luck :frowning:

What does the stations JSON look like?

Hi Ronald. The JSON is mapped correctly, since it can sometimes be mapped correctly to the dropdown. I’m suspecting some kind of weird OnReady behavior…

Sooo… it seems that it’s only an issue when using the previewer. Thanks for the replies :slight_smile:

An easy oversight is to forget to ensure the values are all strings. Preview mode doesn’t seem to log an error if you provide values as numbers so you’ll be left wondering why things aren’t working :slight_smile: