I really need some help on this one.
On my website I have a repeater that is filtered by a few dropdown menus and tags.
One of the dropdown menus is a custom built multiple choice checkbox dropdown (built by this example - essentially a repeater containing a checkbox with options populated by a database).
The problem I am experiencing is that when nothing is selected, obviously the repeater shows no results when you click search (makes sense, since everything in my database has a value in that field (its a tag field in the database). However, I want to make it so that when nothing is selected, it shows all results. Furthermore, if nothing is selected from that multiple choice dropdown menu, but other filters are used - to still give results based on those filters. Obviously the issue im encountering is that by default, if nothing is selected it returns no items since there is nothing in my database without a value in that field. But I cannot wrap my head around how to do this as I am very new to Velo, javascript, etc.
Here’s a picture for example:
Here’s the code that does the search when you click "show me my dream job:
//Main search button to apply all filters used to find a job
export function searchButton_click ( event ) {
search ();
$w ( “#fieldsContainer” ). collapse ();
}
function search () {
$w ( '#pagination1' ). hide ();
let selectedTags = $w ( “#benefits” ). value ;
let continents = ;
$w ( “#continents1” ). forEachItem (( $item , itemData , index ) => {
if ( $item ( ‘#optionCheckbox’ ). checked ) {
continents . push ( $item ( "#optionText" ). text );
}
});
wixData . query ( “jobpostings” )
. hasSome ( ‘field’ , continents )
. and ( wixData . query ( “jobpostings” ). contains ( “location” , String ( $w ( “#locationDropdown” ). value )))
. and ( wixData . query ( “jobpostings” ). contains ( “type” , String ( $w ( “#employment” ). value )))
. and ( wixData . query ( “jobpostings” ). contains ( “language” , String ( $w ( “#languageDropdown” ). value )))
. and ( wixData . query ( “jobpostings” ). contains ( “remote” , String ( $w ( “#checkboxGroup1” ). value )))
. and ( wixData . query ( “jobpostings” ). contains ( “companyType” , String ( $w ( “#companySize” ). value )))
. and ( wixData . query ( “jobpostings” ). hasAll ( “benefits2” , selectedTags ))
// .and(wixData.query(“jobpostings”).contains(“partners”, String($w(“#approved”).value)))
. find ()
. then ( results => {
if ( results . items . length > 0 ) {
// if there are results, hide the element and fill the repeater
$w ( ‘#noResults’ ). hide ();
$w ( “#repeater4” ). data = results . items ;
console . log ( “Yes results” );
} else {
// if there are no results, hide the element (and fill the empty repeater?)
$w ( ‘#noResults’ ). show ();
$w ( “#repeater4” ). data = results . items ;
console . log ( “No results” );
}
//$w(“#repeater4”).data = results.items;
});
}
As you can see, I also have a part of the code that shows a “no results” message in case there are no results.
So at the moment, if you don’t have anything selected in the multiple choice checkbox dropdown, it shows that message because it finds no results - and if you select other filters instead of that one, the same happens (since nothing checked from those boxes = empty value, and every item in my db has values so its not finding anything).
ALSO while we are here, how do i not limit filter repeater results to 50? At the moment, it only shows max 50 results when filtered (i have a large db with some results being 200+). I want it to display all results when filtered, not only 50.
Please help me resolve this!
Would appreciate it a lot.
Thank you!
-Dorijan