Hi everyone,
I’m trying do build a filter to my travel database based on checklists, date pickers, a dropdown and a slider.
So far it was going ok, until I decided to add the slider to filter max price (“f” and “six”)
Currently these factors are absolutely descriptive, case by case.
Is there ant other way you guys suggest me doing it, so that every time I need to add an extra field, I don’t have to think twice?
Probably this is a basic question, but I’m relatively new to programming, this has been a hell of a ride
Thank you so much
export function multifilter() {
let a, b, c, d, e, f = false;
let first, second, third, fourth, five, six;
five = $w("#date2").minDate = $w("#date1").value;
if ($w("#dropdown").value != "") {
a = true;
first = $w("#dropdown").value;
console.log("first")
}
if ($w("#date1").value) {
b = true;
second = $w("#date1").value;
console.log("date", second)
}
if ($w("#checkboxGroup1").selectedIndices[0] >= 0) {
c = true;
third = $w("#checkboxGroup1").value;
console.log("third")
}
if ($w("#checkboxGroup2").selectedIndices[0] >= 0) {
d = true;
fourth = $w("#checkboxGroup2").value;
console.log("fourth")
}
if ($w("#date2").value) {
e = true;
five = $w("#date2").value;
console.log(five)
}
if ($w("#slider").value) {
f = true;
six = $w("#slider").value;
console.log(six)
}
if (a && b && c && d && e && f) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second)
.le("date_back", five)
.hasSome('destinationCountry', third)
.hasSome('stars', fourth)
.le('price', six))
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first)
.ge("date_go", second)
.le("date_back", five)
.hasSome('destinationCountry', third)
.hasSome('stars', fourth)
.le('price', six))
}
}
if (a && b && c && d && f) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second)
.hasSome('destinationCountry', third)
.hasSome('stars', fourth)
.le('price', six))
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first)
.ge("date_go", second)
.hasSome('destinationCountry', third)
.hasSome('stars', fourth)
.le('price', six))
}
}
if (b && c && d && e && f) {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second)
.le("date_back", five)
.hasSome('destinationCountry', third)
.hasSome('stars', fourth)
.le('price', six))
}
if (a && b && c && e && f) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second)
.le("date_back", five)
.hasSome('destinationCountry', third)
.le('price', six))
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first)
.ge("date_go", second)
.le("date_back", five)
.hasSome('destinationCountry', third)
.le('price', six))
}
}
if (a && b && d && e && f) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second)
.le("date_back", five)
.hasSome('stars', fourth)
.le('price', six))
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first)
.ge("date_go", second)
.le("date_back", five)
.hasSome('stars', fourth)
.le('price', six))
}
}
if (a && c && d && e && f) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter()
.le("date_back", five)
.hasSome('destinationCountry', third)
.hasSome('stars', fourth)
.le('price', six))
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first)
.le("date_back", five)
.hasSome('destinationCountry', third)
.hasSome('stars', fourth)
.le('price', six))
}
}
if (a && b && c && f) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second)
.hasSome('destinationCountry', third)
.le('price', six))
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first)
.ge("date_go", second)
.hasSome('destinationCountry', third)
.le('price', six))
}
}
if (c && d && e && f) {
$w('#dataset1').setFilter(wixData.filter()
.le("date_back", five)
.hasSome('destinationCountry', third)
.hasSome('stars', fourth)
.le('price', six))
}
if (b && c && d) {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second)
.hasSome('destinationCountry', third)
.hasSome('stars', fourth)
.le('price', six))
}
if (a && c && d && f) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter()
.hasSome('destinationCountry', third)
.hasSome('stars', fourth)
.le('price', six))
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first)
.hasSome('destinationCountry', third)
.hasSome('stars', fourth)
.le('price', six))
}
}
if (a && d && e && f) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter()
.le("date_back", five)
.hasSome('stars', fourth)
.le('price', six))
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first)
.le("date_back", five)
.hasSome('stars', fourth)
.le('price', six))
}
}
if (b && d && e && f) {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second)
.le("date_back", five)
.hasSome('stars', fourth)
.le('price', six))
}
if (a && b && d && f) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second)
.hasSome('stars', fourth)
.le('price', six))
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first)
.ge("date_go", second)
.hasSome('stars', fourth)
.le('price', six))
}
}
if (b && c && e && f) {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second)
.le("date_back", five)
.hasSome('destinationCountry', third)
.le('price', six))
}
if (a && c && e && f) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter()
.le("date_back", five)
.hasSome('destinationCountry', third)
.le('price', six))
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first)
.le("date_back", five)
.hasSome('destinationCountry', third)
.le('price', six))
}
}
if (a && b && e && f) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second)
.le("date_back", five)
.le('price', six))
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first)
.ge("date_go", second)
.le("date_back", five)
.le('price', six))
}
}
if (a && b && f) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second)
.le('price', six))
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first)
.ge("date_go", second)
.le('price', six))
}
}
if (c && d && f) {
$w('#dataset1').setFilter(wixData.filter()
.hasSome('destinationCountry', third)
.hasSome('stars', fourth)
.le('price', six))
}
if (d && e) {
$w('#dataset1').setFilter(wixData.filter()
.le("date_back", five)
.hasSome('stars', fourth)
.le('price', six))
}
if (a && c && f) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter()
.hasSome('destinationCountry', third)
.le('price', six))
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first)
.hasSome('destinationCountry', third)
.le('price', six))
}
}
if (b && d && f) {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second)
.hasSome('stars', fourth)
.le('price', six))
}
if (c && e && f) {
$w('#dataset1').setFilter(wixData.filter()
.le("date_back", five)
.hasSome('destinationCountry', third)
.le('price', six))
}
if (b && e && f) {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second)
.le("date_back", five)
.le('price', six))
}
if (a && d && f) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter()
.hasSome('stars', fourth)
.le('price', six))
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first)
.hasSome('stars', fourth)
.le('price', six))
}
}
if (a && e && f) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter()
.le("date_back", five)
.le('price', six))
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first)
.le("date_back", five)
.le('price', six))
}
}
if (b && c && f) {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second)
.hasSome('destinationCountry', third)
.le('price', six))
}
if (a) {
if (first == "ALL") {
$w('#dataset1').setFilter(wixData.filter())
} else {
$w('#dataset1').setFilter(wixData.filter()
.eq('originCountry', first))
}
}
if (b) {
$w('#dataset1').setFilter(wixData.filter()
.ge("date_go", second))
}
if (c) {
$w('#dataset1').setFilter(wixData.filter()
.hasSome('destinationCountry', third))
}
if (d) {
$w('#dataset1').setFilter(wixData.filter()
.hasSome('stars', fourth));
}
if (e) {
$w('#dataset1').setFilter(wixData.filter()
.le("date_back", five))
}
if (f) {
$w('#dataset1').setFilter(wixData.filter()
.le('price', six)
)
} else {
$w('#dataset1').setFilter(wixData.filter())
}
}