Display "sorry no results message" after filtering

Hi guys,
I got a search module, like property search, with dropdown, and a "find button, all results appears in a repeater.i would like to display a message no results in case of no data.
here is my code, please can you tell me with code i have to add and where, super thx in advance…


import { local } from ‘wix-storage’;

import wixData from ‘wix-data’;

$w.onReady(function () {

var sameWord = local.getItem("searchWord");
$w("#input1").value = sameWord;
$w("#input1").placeholder = sameWord;
  $w('#dataset1').onReady(function () {

    search();

});

});

export function button5_click() {
search();
}

function search() {
wixData.query(‘Codicipostaliservizioadomicilio’)
.contains(‘title’, $w(“#input1”).value)
.or(wixData.query(‘Codicipostaliservizioadomicilio’).eq(‘codicePostale’, $w(“#input1”).value))
.find()
.then(res => {
$w(‘#repeater1’).data = res.items;

    });  

}

Hi there :wave:t2: I do something similar on my site. What I do is have my repeater on a strip, and my “no results” messaging on a different strip, set to collapsed on load. When there are no results I collapse the repeater strip, and expand the strip that says “no results”.
But you could do the same with something as simple as hiding/showing a text box.

In your code, you’ll want to replace this section:

.then(res => {             
    $w('#repeater1').data = res.items;          

}); 

With this code:

.then(res => {
    if (res.items.length > 0) {
    // If the query HAS results, do this:         
        $w('#repeater1').data = res.items;
    } else { 
    // If the query has NO results, do this:
        $w('#repeaterStrip').collapse(); 
        $w('#noResultsStrip').expand(); 
    }
})

Good luck!

Thank you so much! You have no idea how much you’ve helped me. It works great!