I'm trying to build a search code and in the meantime I just managed to do it with a search bar and a drop down options.
I have to add a checkbox option and a between option (for price) and i cant find a way to do it.
This is the code:
let sameWord = local.getItem(“searchWord”);
$w(“#searchBar”).value = sameWord;
$w(“#searchBar”).placeholder = sameWord;
let sameType = local.getItem(“typeV”);
$w("#typeBar").value = sameType;
$w("#typeBar").placeholder = sameType;
let sameType2 = local.getItem(“type2V”);
$w("#typeBar2").value = sameType2;
$w("#typeBar2").placeholder = sameType2;
$w(‘#apartmentId’).onReady(function () {
search();
searchF();
searchH();
$w.onReady(function () {
import wixData from ‘wix-data’;
import wixSite from ‘wix-site’;
})
});
export function searchButton_click(event) {
search();
searchH();
searchF();
}
export function search () {
let nDataV = wixData.query(‘apartments’);
/* let acBoxV = $w(“#acBox”).value;
let rangeStartSqm = $w(“#sqmMinBar”).value;
let rangeEndSqm = $w(“#sqmMaxBar”).value;
let sameType2 = $w(“#typeBar2”).value;
*/
nDataV.contains('name', $w("#searchBar").value)
.or(nDataV.contains('nighberhood', $w("#searchBar").value))
.and(nDataV.contains('typeSOrR', $w("#typeBar2").value))
.and(nDataV.contains('type', $w("#typeBar").value))
// .and(aDataV.ge(‘sqm’, rangeStartSqm))
// .and(boxName.contains(‘ac’, $w(“#acBox”).value))
// .and(sDataV.eq(“ac”, acBoxV))
.find()
.then(res => {
$w('#repeater1').data = res.items
if (res !== null) {
$w("#repeater1").expand();
}
}
);
}
and one other thing, the search is on the home page and it send you to a search results page.
the drop down options are on request, and if i don’t put one of the option, on the search results window, it showing “undefined”.
this is the code of the home page :
export function typeBar2_change_1(event) {
let type = $w(“#typeBar2”).value;
local.setItem("typeV", type);
}
export function typeBar_change_1(event) {
let type = $w(“#typeBar”).value;
local.setItem("typeV", type);
}
export function searchbar_change_1(event) {
let word = $w(“#searchbar”).value;
local.setItem("searchWord", word);
}
export function searchbar_keyPress_1(event) {
if(event.key === “Enter”){
searchbar_change_1();
typeBar2_change_1();
typeBar_change_1();
wixLocation.to('/search') ;
}
}
export function searchButton_click(event) {
wixLocation.to('/search') ;
}