Hi,I have made my own search bar using code, input boxes and repeaters for a filter.I am stuck in the final steps, the search works great, but once my search results load, i have to go back to another page so i can search again, its because of the URL of my search results page and my code.Can someone please point me in the right direction? Site code;
import {session} from 'wix-storage';
import {local} from 'wix-storage';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
import wixData from 'wix-data';
//Continue shopping to previous URL
let previousURL = session.getItem('previousURL');
session.setItem('previousURL', wixLocation.url);
export function getPreviousPageLink() {
if (previousURL === session.getItem('previousURL')) {
wixLocation.to('/')
} else {
wixLocation.to(previousURL);
}
}
export function continueShopping_click(event) {
getPreviousPageLink();
return false;
}
//Home logo link to homepage
export function homeLogo_click(event) {
wixLocation.to("/home");
}
//GoTo results page and send input to URL query
export function searchButtonHeader_click(event) {
wixLocation.to("/Stores/Products?search="+$w("#searchFieldHeader").value);
}
//GoTo results page upon click or enter
$w.onReady(function (){
$w("#searchFieldHeader").onKeyPress((event, $w) => {
if (event.key === "Enter") {
wixLocation.to("/Stores/Products?search="+$w("#searchFieldHeader").value);}
})
//Mobile view edit
if(wixWindow.formFactor === "Mobile") {
$w('#searchFieldHeader').collapse()
$w('#searchIconHeader').collapse()
$w('#searchButtonHeader').collapse()
}
$w('#searchButtonMobile').onClick(() => {
if( $w("#searchFieldHeader").collapsed ) {
$w("#searchFieldHeader").expand();
}
else {
$w("#searchFieldHeader").collapse();
}
if( $w("#searchButtonHeader").collapsed ) {
$w("#searchButtonHeader").expand();
}
else {
$w("#searchButtonHeader").collapse();
}
if( $w("#searchIconHeader").collapsed ) {
$w("#searchIconHeader").expand();
}
else {
$w("#searchIconHeader").collapse();
}
})
})
Page code;
import wixWindow from 'wix-window';
import {local} from 'wix-storage';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
//---------------------------------------------
function filter(title) {
$w('#dynamicDataset')
.setFilter(wixData.filter().contains('name',title));
}
// Re run search using value in search bar.
export function searchButtonPage_click(event) {
filter($w('#searchFieldPage').value);
}
$w.onReady(function () {
// Load query
let query = wixLocation.query;
// Get search term from query
let searchWord = query.search;
// Add search term to input element
$w('#searchFieldPage').value = searchWord;
// Show search Results
$w('#input1').value = "'"+searchWord+ "'"
// Initially filter based on passed search phrase
filter(searchWord);
// Adjust view if page is displayed on mobile.
if(wixWindow.formFactor === "Mobile") {
$w("#column5").collapse();
$w('#searchFieldPage').collapse()
$w('#searchIconPage').collapse()
$w('#searchButtonPage').collapse()
}
// Adjust view if page is displayed on Desktop.
if(wixWindow.formFactor === "Desktop") {
$w('#searchFieldPage').collapse()
$w('#searchIconPage').collapse()
$w('#searchButtonPage').collapse()
}
})
Screenshot of searchpage with URL
Thank you
Matt