Search bar that shows an error if doesn’t find any result?

hi all, do you know how to add a text that says ”no results found” if a search bar doesn’t show any result from a repeater linked to a database?

i think it must be done with a text that is collapsed on load but not sure…

can anybody help me?
thanks

Hi,

You can check for the length of the results and if it equals to 0 show a text, either by expand() or show().
See the code snippet below:

wixData.query("myCollection") .find() 
  .then( (results) => {
    if (results.length > 0) {
    $w('#noResText').show();
   }
   else {
   $w('#noResText').hide();
   }
   } ) 
   .catch( (err) => {
    let errorMsg = err; } );
1 Like

I tried it but not working yet :frowning:

Hi,
Can you share your code and explain what is occurring /not occurring ?

1 Like

its working! :)))))
Thanks a lot!

Hi Im having the same problem too and its driving me mad, can i send a screenshot or invite one of you to be a contributor to have a look at it please before i pull all of my hair out infrustration :slight_smile: x

1 Like

Hello Ido, this code works perfectly using query, but what about if using setFilter? Which code will Be the best?
Thanks

Hello, what is #noResText?

Wix code says “noResText is not a valid selector”.