I try to get a 5 dropdown to be able to work both independently and together. After adding .between() in for dropdown#4 and 5, it now only work if there is an input for #4 and #5, the #1-#3 work won't independently anymore, I'm a absolute beginner at this, any help would be much appreciate, Thank you everyone.
import wixData from 'wix-data';
export function button11_click(event) {
search();
}
function search() {
wixData.query("Properties")
.contains("sellorrent", String($w("#dropdown0").value))
.and(wixData.query("Properties").contains("province", String($w("#dropdown1").value)))
.and(wixData.query("Properties").contains("PropertyType", String($w("#dropdown2").value)))
.and(wixData.query("Properties").between("price", parseFloat($w('#dropdown3').value), parseFloat($w('#dropdown4').value)))
.find()
.then(results => {
$w("#repeater1").data = results.items;
});
}
//Reset Filter
export function resetButton_click_1(event) {
$w("#propertiesDataset").setFilter(wixData.filter())
$w("#dropdown0").value = undefined;
$w("#dropdown1").value = undefined;
$w("#dropdown2").value = undefined;
$w("#dropdown3").value = undefined;
$w("#dropdown4").value = undefined;
$w("#searchBar").value = undefined
}
Something like:
import wixData from 'wix-data'; let query = wixData.query('CollectionName'); let resultslimit = 1000; function runQuery(){ if($w('#filter1').value)){query = query.contains('field1', $w('#filter1').value);} if($w('#filter2').value)){query = query.contains('field2', $w('#filter2').value);} if($w('#filter3').value)){query = query.contains('field3', $w('#filter3').value);} if($w('#filter4').value)){query = query.contains('field4', $w('#filter4').value);} if($w('#minimum').value && $w('#maximum').value){ query = query.between('field5', Number($w('#minimum').value) ,Number($w('#maximum').value) ); } else if($w('#minimum').value){ query = query.ge('field5', Number($w('#minimum').value)); } else if($w('#maximum').value){ query = query.le('field5', Number($w('#maximum').value)); } return query.limit(resultslimit).find(); } $w.onReady(() => { $w('#searchButton').onClick(event => { return runQuery() .then(r => { const items = r.items; if(items.length > 0){ $w('#repeater1').data = r.items; } }) }) })