Search input bar (delete the value history)

Hi there.

I have a working search input bar and it filters correctly based on value.
My problem is when i go to other page and come back to the page where
the search input bar is there, the last (history) search value is still there.
Example: I search word “Work”, then it search. When i leave the page and comeback the word “Work” is still there. It should be blank again.

How to clear it once i leave the page automatically? Thank you

Hi,

Instead of clearing it once you leave, you can clear the search text box when the page is ready:

 $w.onReady( function() {
  $w("#search").value="";
   } ); 

Good Luck,

Mustafa

Hi,

Can you specify the page name where it happens?

Thank you for the reply. Appreciated!

I think its not a good option to clear the search bar once its load because my code is the reverse of that.

My home page and my tour page has both search bar. I pushed my home page search bar to link to tour page search bar using wix location. So what ever i typed on my home search bar the value will be the same on my tour page search bar. Now i used onReady function to run the filter (search) once the page load. It works actually. The only problem is it leaves the last value unless if i used home search bar again (empty).

Here are my current codes

HOME SEARCH BAR CODE
export function searchBar_keyPress(event, $w) {
if (event.key === “Enter”) {
let word = $w(“#searchBar”).value;
local.setItem(“searchWord”, word);
wixLocation.to(‘/JapanTours’);

}
}

TOUR PAGE SEARCH BAR CODE
$w.onReady( function () {
var sameWord = local.getItem(“searchWord”);
$w(“#iTitle”).value = sameWord;
$w(“#dataset1”).onReady( function () {
filter($w(‘#iTitle’).value, lastFilterCategory);
})
});

*this both page using

import {local} from ‘wix-storage’;
import wixData from ‘wix-data’;

Am i missing something? However, it’s really not a big deal. Its not just good look when someone visit the tour page directly with a value already. Thank you very much for the big help.

Did you get a solution you can share? Clear search bar input when you leave the page.

Did anybody get to this? I’m having the same problem.

Rainey this is how I am clearing the search bar after leaving the result page and it works.