Hello community,
I want to create a search bar that displays the result in a second page of my site.
So I inserted a code on my home page that retrieves and transmits on the second page the information chosen by the user in my 3 dropdown.
Once on the second page the user selection is displayed but the search is not carried out automatically. To launch it I have to click on each dropdown and click on my search button.
Do you have a solution so that the result is automatically displayed when I arrive on the result page??
Hoping to have succeeded in making me understand.
I thank you in advance for your help
The code on the search page :
import {local} from ‘wix-storage’;
import wixLocation from ‘wix-location’;
$w.onReady( function () {});
export function SearchButton_click(){
let text = $w(“#dropdown1”).value;
let text2 = $w(“#dropdown2”).value;
let text3 = $w(“#dropdown4”).value;
local.setItem(“searchtext”, text);
local.setItem(“searchtext2”, text2);
local.setItem(“searchtext3”, text3);
wixLocation.to(`/page2);
}
The code on the result page:
import wixData from ‘wix-data’;
import {local} from ‘wix-storage’;
$w.onReady( function () {
var sameTexte = local.getItem(“searchtext”);
var sameWord = local.getItem(“searchtext2”);
var sameTitle = local.getItem(“searchtext3”);
$w("#dropdown1").value = sameTexte;
$w("#dropdown2").value = sameWord;
$w("#dropdown4").value = sameTitle;
$w("#dropdown1").placeholder = sameTexte;
$w("#dropdown2").placeholder = sameWord;
$w("#dropdown4").placeholder = sameTitle;
$w('#dataset3').onReady( **function** () {
search();
});
});
export function SearchButton_click() {
$w(“#dropdown1”).value
$w(“#dropdown2”).value
$w(“#dropdown4”).value
search();
}
function search(){
wixData.query(‘Etablissements’)
var filter1 = wixData.filter()
filter1.filterTree.$and[0] = {}
filter1.filterTree.$and[1] = {}
filter1.filterTree.$and[2] = {}
$w('#dropdown1').onChange(() => {
let departement = $w(‘#dropdown1’).value;
if (departement === ‘departement’) {
filter1.filterTree.$and[0] = {}
} **else** {
filter1.filterTree.$and[0] = {
‘departement’: departement
}
}
})
$w('#dropdown2').onChange(() => {
let activite = $w(‘#dropdown2’).value;
if (activite === ‘activite’) {
filter1.filterTree.$and[1] = {}
} **else** {
filter1.filterTree.$and[1] = {
‘activite’: activite
}
}
})
$w(‘#dropdown4’).onChange(() => {
let certification = $w(‘#dropdown4’).value;
if (certification === ‘certification’) {
filter1.filterTree.$and[2] = {}
} **else** {
filter1.filterTree.$and[2] = {
‘certification’: certification
}
}
})
$w('#SearchButton').onClick(() => {
filter();
})
function filter() {
console.log(filter1.filterTree.$and)
$w('#dataset3').setFilter(filter1)
}}