Wix code SDK Warning: The text parameter cannot be set to null or undefined

Hi everybody!
First of all, thank you so much for taking the time to read this!


What I am trying to do: code my lightbox so that the users can check what are our delivery prices and times in their country. There is one collection called “Lieferkosten”, that combines this information in 4 columns/fields: Country (land), Region (region), Delivery fee (versandkosten) and Delivery time (versanddauer). The names in brackets are the respective fieldkeys.
Under the two dropdowns where users can select their region and country, there are 3 textboxes that should display: #text55 (selected country name), #text56 (the delivery fee that corresponds to the selected country), #text57 (the delivery time that corresponds to the selected country)

What works so far: The client clicks on the #dropdown2 to select what region he comes from. Upon user input (selection of a region) an On Change function causes the #dropdown1 to be activated and display all the countries that belong to this selected region. The country name selected on #dropdown1 is shown on textbox #text55 (however not thanks to code but to the API connection)

Problem:
#text56 and #text57 either display nothing or remain unchanged.

I have tried several solutions, checked the fieldkeys many times and they do correspond to what is in the collection. On my latest attempt (which is the code below, where I only tested it on #text56) I get the error message: “Wix code SDK Warning: The text parameter of “text56” that is passed to the text method cannot be set to null or undefined.” and on the developer tool I find: “TypeError: Cannot read property ‘versandkosten’ of undefined”

...
export function dropdown2_change(event) {
    uniqueDropDown2();
$w("#dropdown1").enable();
    NewQuery();
$w('#text56').text = NewQuery()

}
function NewQuery() {
 let myTextQuery = $w('#dropdown2').value
   wixData.query("Lieferkosten").eq("versandkosten", myTextQuery) // the first element here is the field key, not the field name.
.find()
.then((results) => {
 if(results.items.length > 0) {
 let item = results.items[0];
 let secondText = item.versandkosten; //the field key of the second column
 let thirdText = item.versanddauer; //the field key of the third column
    }else{
 //put here the code you want to execute in case of no match.
    }
})}

I´m very new to corvid and don´t know that much about coding so would really appreciate any corrections or tips even if they are an entirely new suggestion of code :slight_smile:

You need to make the dropdown onChange() async function with $(“#text56”).text = await newQuery(), and to add a “return” to the newQuery().
It is a promise after all.

1 Like

To add to J. D. post above, you can have a read of using promises in Wix to help you understand it more by looking at this page here. https://support.wix.com/en/article/corvid-working-with-promises

Thank you both for the quick replies!!! I´ll take a read, make the change and let you know how it went :slight_smile: