I am kind frustrated with this actually! Trying this since weeks, even with a Code Pro of my work! So i have a start page with a search and result are at results page! In the start page i managed to search just by click “Enter”, on the result page in the searchBar i cant manage to make a search just easily by clicking "Enter! OnClick event in the searchBar is activated! This is the Code I am Using so far:
Thx for any help! Martin
The Code on the Start Page works fine!!
import {local} from ‘wix-storage’ ;
import wixLocation from ‘wix-location’ ;
function runSearch(){
$w.onReady( function () {
});
// Add your code for this event here:
$w( “#loadingGif” ).show();
let word = $w( “#searchBar” ).value;
local.setItem( "searchWord" , word);
wixLocation.to(`/produktsuche`);
}
$w.onReady( function () {
$w( “#searchBar” ).onKeyPress( (event) => {
if (event.key === “Enter” ){
runSearch();
}
})
});
The Code on this page doesnt work at at all!
import {local} from ‘wix-storage’ ;
import wixData from ‘wix-data’ ;
$w.onReady( function () {
// AXEL
$w( “#searchBar” ).onKeyPress( (event) => {
if (event.key === “Enter” ){
console.log( “Enter was pressed!” )
//search();
}
});
// End AXEL
var sameWord = local.getItem( “searchWord” );
$w( "#searchBar" ).value = sameWord;
//$w(“#searchBar”).placeholder = sameWord;
$w( '#dataset3' ).onReady( **function** () {
search();
});
});
let debounceTimer;
export function searchBar_click() {
//Add your code for this event here:
//Add your code for this event here:
$w( "#loadingGif" ).show();
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
$w( "#dataset3" ).setFilter(wixData.filter().contains( "title" , $w( '#searchBar' ).value)
.or(wixData.filter().contains( "shop" , $w( '#searchBar' ).value)))
.then(() => {
count();
})
}, 200 );
search();
}
function count() {
let total = $w( ‘#dataset3’ ).getTotalCount();
if (total > 1 ) {
$w( '#textResults' ).text = `${total} nachhaltige Produkte gefunden.`;
$w( "#loadingGif" ).hide();
$w( '#textResults' ).show();
}
if (total === 1 ) {
$w( ‘#textResults’ ).text = ${total} nachhaltiges Produkt gefunden.
;
$w( “#loadingGif” ).hide();
$w( ‘#textResults’ ).show();
}
if (total === 0 ) {
$w( ‘#textResults’ ).text = “Leider nichts gefunden. Bitte probiere einen ähnlichen Begriff” ;
$w( “#loadingGif” ).hide();
$w( ‘#textResults’ ).show();
}
}
function search() {
wixData.query( 'Produkte2020NEU' )
.contains( 'title' , $w( "#searchBar" ).value)
.or(wixData.query( 'Produkte2020NEU' ).contains( 'shop' , $w( "#searchBar" ).value))
.or(wixData.query( 'Produkte2020NEU' ).contains( 'kategorie' , $w( "#searchBar" ).value))
.limit( 10 )
.ascending ( "preis" )
.find()
.then(res => {
$w( ‘#repeater3’ ).data = res.items;
});
}
export function picture1_click(event) {
// Add your code for this event here:
if ($w( ‘#box1’ ).collapsed) {
$w( ‘#box1’ ).expand();
} else {
$w( ‘#box1’ ).collapse();
}
}
export function vectorImage71_click(event) {
// Add your code for this event here:
if ($w( ‘#box2’ ).collapsed) {
$w( ‘#box2’ ).expand();
} else {
$w( ‘#box2’ ).collapse();
}
}
export function text998_click(event) {
// Add your code for this event here:
if ($w( ‘#box2’ ).collapsed) {
$w( ‘#box2’ ).expand();
} else {
$w( ‘#box2’ ).collapse();
}
}
export function button166_click(event) {
// Add your code for this event here:
if ($w( ‘#box6’ ).collapsed) {
$w( ‘#box6’ ).expand();
} else {
$w( ‘#box6’ ).collapse();
}
}