Hi there i managed to create a search bar for store products and the results appearing on a results page, now what i need is to add the search into the header to make persistent thought the site and finally i need a message if nothing found. This is my site example : https://lucasgariglia.wixsite.com/website-7 simply search from the home products “luca” or “sgariglia” and thank you for the support so far. Luca.
Hi Luca,
You can pass the search parameter using wixLocation.to
see here
To get the search parameters in the results page use wixLocation.query
Hi Ido, as i mentioned from the home page the search bar works by redirecting me to the results page, but once i get there the search doesn’t work anymore. This my code in the home page: import {local} from ‘wix-storage’;
import wixLocation from ‘wix-location’;
$w.onReady( function () {
});
export function searchButton_click() {
let word = $w(“#searchBar”).value;
local.setItem("searchWord", word);
wixLocation.to(`/results`);
}
and on the results : import { local } from ‘wix-storage’;
import wixData from ‘wix-data’;
var sameWord ;
sameWord = local.getItem(“searchWord”);
$w.onReady( function () {
$w(“#searchBar”).value = sameWord;
// $w(“#searchBar1”).placeholder = sameWord;
$w(‘#dataset1’).onReady( function () {
console.log(sameWord )
search();
});
});
export function searchButton1_click() {
search();
}
function search() {
wixData.query(‘Stores/Products’)
.contains(‘name’, $w(“#searchBar1”).value)
.find()
.then(res => {
$w(‘#repeater1’).data = res.items;
});
}
Thanks.