I have used Naylie’s code to search a database (Thank you Nayeli) and have modified slightly as I am using a database automatically created via wix.stores
Home Page Code
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(/search-results
);
}
**Results Page Code **
import {local} from ‘wix-storage’;
import wixData from ‘wix-data’;
$w.onReady( function () {
var sameWord = local.getItem(“searchWord”);
$w(“#searchBar”).value = sameWord;
$w(“#searchBar”).placeholder = sameWord;
$w(‘#dataset1’).onReady( function () {
search();
});
});
export function searchButton_click() {
search();
}
function search() {
wixData.query(‘Stores/Products’)
.contains(‘name’, $w(“#searchBar”).value)
.or(wixData.query(‘Stores/Products’).eq(‘price’, $w(“#searchBar”).value))
.find()
.then(res => {
$w(‘#repeater1’).data = res.items;
});
}
Try as I might i cannot get
.or(wixData.query(‘Stores/Products’).eq(‘price’, $w(“#searchBar”).value))
to work in conjunction with the ‘.contains’ - it returns 20 out of 45 products - and has no relation to the search??
It doesn’t appear to be clearing the wix-storage either but rather holding on to the initial user input, i.e ‘pink’ - is there a way to make the search bar return to ‘Search’ once the query has been fulfilled??
Also, I would love to have a ‘No Products Found’ if there’s nothing matching either criteria.
I have looked through lots of online help and suggestions and I confess - I got nothing!!
Please help, I am pulling my hair out - I have been at this for two days solid …
Thanks so much for your help
NB: I didn’t underline this - the machine did
wixLocation.to(/search-results
);