Database Collection Query Question on If Else statement

Ive put together a simple query to display search results in a repeater, Im trying to figure out how to handle the case where no matching items are found and display an error message. The search part works when my search matches an item in the database, but when no matching items are found nothing shows up, the repeater isnt filled out or shown. Any help is significantly appreciated!

export function button2_click() {
search();
}
function search() {
wixData.query('TravelLocations')
.contains("location", $w("#input4").value)
.find()
.then( (results) => {
if (results.items.length > 0) {
$w('#repeater1').data = results.items;
$w('#repeater1').show();
}
else {
$w("#box2").show
}
})
}

Hi Collin!

The code looks good actually.
It seems like when you click $w(‘#button2’) a query is triggered, and if there are any results (one or more) you push the data into the repeater, then show the repeater itself.
When no results are returned, show $w(‘#box2’), the error message I presume.
If there aren’t any results the repeater shouldn’t show anything - that is unless you want it to show something specifically when there are no matching results.

Please tell us more about your intentions and use case so we can assist :slight_smile:

Doron.