Database query no results message

Hey people,

I have a simple data base query to search a tracking number.
The tracking number is entered into input box and attached to a search button.
The results (only one) is loaded into a repeater.

The code is as

import wixData from “wix-data” ;

$w.onReady( function () {

});

export function searchbutton_click(event) {

wixData.query( “Tracking” )

.contains( “title” , $w( “#trackinginput” ).value)
.find() // Run the query
.then(res => {
$w( “#repeater1” ).data = res.items;
$w( “#repeater1” ).expand();

}
);

}

No problems here.
However, I would like to show a container box [noresultsmessage] if there are no results.

I am not sure what code to use and would really appreciate any help.

Cheers
Stephen

Put a box or a tex somewhere in your form with a text like “No results found.”. Make it hidden. Let’s say it’s called “boxNoResult”. Your code would look something like:

export function searchbutton_click(event) {   
wixData.query("Tracking")      
.contains("title", $w("#trackinginput").value)   
.find()  // Run the query   
.then(res => {         
if(res.items > 0){
    $w("#repeater1").data = res.items;             
    $w("#repeater1").expand();      
    }    
    );  
    }
}
else {
    $w("#repeater1").hide();
    $w('#boxResult').show();
}

Hi, I need help!

I’ve been working on this code for days. I’ve tried a million ways to show a “No Results” message if query comes back = 0. I did it in a million different ways and still the “No Results” text box doesn’t show up. Can you verify my code and see what am I doing wrong?

import wixData from ‘wix-data’ ;
$w ( ‘#resetButton’ ). hide ();

$w . onReady ( function () {

});

export function searchButton_click ( event ) {
search ();
}

function search ( ) {

wixData . query ( "Courses1" ) 
. contains ( "order" , String ( $w ( '#dropdown1' ). value )) 

. and ( wixData . query ( “Courses1” )). contains ( “location” , String ( $w ( ‘#dropdown2’ ). value ))
. find ()
. then ( results => {
$w ( ‘#listRepeater’ ). data = results . items ;
});

$w ( '#resetButton' ). show (); 
$w ( '#resetButton' ). enable (); 
$w ( '#searchButton' ). hide (); 

}

export function resetButton_click ( event ) {
$w ( ‘#dynamicDataset’ ). setFilter ( wixData . filter ());
$w ( ‘#dropdown1’ ). value = undefined ;
$w ( ‘#dropdown2’ ). value = undefined ;
$w ( ‘#searchButton’ ). show ();
$w ( ‘#searchButton’ ). enable ();
$w ( ‘#resetButton’ ). hide ();
}
export function searchbutton_click ( event ){
search ();
}
function find ( ) {

wixData . query ( “Courses1” )
. contains ( “order” , String ( $w ( “#dropdown1” ). value ))
. and ( wixData . query ( “Courses1” )
. contains ( “location” , String ( $w ( “#dropdown2” ). value )))
. find () // Run the query
. then ( results => {
if ( results . items . length > 0 ) {
$w ( ‘#listRepeater’ ). data = results . items ;

} else {
$w ( “#listRepeater” ). collapse ();
$w ( ‘#noresultsText’ ). expand ();
console . log ( “No Results” )
}
})
}