Wix code SDK warning

I have recently made a few changes to my site, one being disconnecting elements from the dataset, and connecting it all via Javascript.

When connecting text elements this way I have received the following message for each of the text elements which are empty in the database.

‘Wix code SDK warning: The text parameter of “text49” that is passed to the text method cannot be set to null.’

(some products will have every box filled, whereas others may only have 1 or 2, it depends on the product)

Is there something I can add to the code, so if this field is empty it won’t show as an error or warning?

This is a snippet of the code…

$w(‘#text54’).text = item.supplier5;
$w(‘#text53’).text = item.priceUrl5;
$w(‘#text52’).text = item.sizeText5;

Thanks

Are these elements unique or are they being filled via the .data property of a repeater?

If they are unique elements, you can check if the data you are querying from your collection has the property before setting the text value.

Example Code

$w.onReady(function () {
    //...
   
    if (item.supplier5) { //Checks if "supplier5" field has a value
        $w(‘#text54’).text = item.supplier5;
    } else {
        //Handle case when field is empty (i.e. Hide or collapse the element)
    }
    //Add checks for additional fields if necessary

});

Works, thank you for help

1 Like