search/query not running in onready

I have a page which contain a search box that displays its results in a repeater on the same page.
From this page you can click off to a separate page, but if you hit a back button, you come back to the search page and the search box is populated with the search keyword that was there when you left the page. But the search does not re-run even though its in the onready part of the page code.

What I want is for a user to come back to the search, where they left it. But currently all I get is the search box populated and all the contents of my collection displayed.
Any thoughts?

Thanks

You can save the last search keyword using storage API and populate it when the page is loaded on the onReady function.

@Tai Many thanks for your response, that is the way I am doing it. The onready funciton has that call in it, and in the console I can see that the query runs, but the results never get displayed in the repeater.

You should also set the results to the repeater . It’s a similar case to the scenario mentioned here . The difference is that you should use the item saved on your local storage as your keyword when querying your collection.

@Tal - Ah yes that forum post is one that I have viewed many times! Its great. Yes thats what I am doing, refereing the the stored value, in a query that is within the on ready function. Viewing the results to console.log works, and they are set to the repeater, but alas no show on the repeater.

Can you please share the code so that we can have a look?
Thanks

@Tal Here is the code from the onready section that I am having issues with. Added some comment lines in to help explain.

var searchReturn = session.getItem(“inputsearchWord”);
//Getting the search word using the session getitem function.

//Next an if statement to see if the searchReturn word is populated or not.

if ( searchReturn === null ) {
console.log(“searchReturn is empty”);

    }  **else**  { 

//Excuse the console.logs but was just seeing where it loaded too.
console.log(searchReturn, “This is the search Return value in the onready query”);
//set the input search box value to be the word from the getitem function.
$w(‘#input1’).value = searchReturn;

       **let**  searchValue = searchReturn; 

//Run the search
wixData.query(‘Members’)
.contains(‘lastName’, searchValue)
.or(wixData.query(‘Members’)
.contains(‘firstName’, searchValue))
.or(wixData.query(‘Members’)
.contains(‘city’, searchValue)
.or(wixData.query(‘Members’)
.contains(‘roleLevel’, searchValue)
.or(wixData.query(‘Members’)
.contains(‘company’, searchValue)
.or(wixData.query(‘Members’)
.contains(‘priRegion’, searchValue)
.or(wixData.query(‘Members’)
.contains(‘role’, searchValue))))))
.find()
.then((results) => {
console.log(results, “this is the reults line under Then”)
//All the console.logs in this section show just the search results from the collection I am querying, but the // repeater shows all the items in the collection, not just the search results.
arraySearchresults = results.items;
console.log(arraySearchresults, “Onready reaults passed to propsinfo”);
$w(‘#repeater1’).data=arraySearchresults;
console.log(“After Onready results”)

    }) 
    . **catch** ((err) => { 

let errorMsg = err;
});

    }