Hello.
I cannot stress how much help I need at the moment.
I have a couple of dropdown menus which I use to filter a repeater. The options in each drop down are directly pulled from my main database and are displayed as unique values (non-duplicates).
The only thing I need to do in order to complete this project of mine is to add an “Any” option to the dropdowns. I have no idea how to do this just through code. Once again, the dropdown options are pulled directly from my main database and set as unique items to remove the duplicates.
I would REALLY appreciate help asap, as the only thing I need to do is add the “any” option somewhere in this code, with its value being 0 since basically this option shouldn’t filter anything. (My dropdowns filter after you click on a search button). Here’s my messy, ducktaped-together code. Please help me
import wixData from ‘wix-data’ ;
//start of JobField dropdown - work please i beg of
$w . onReady ( function () {
wixData . query ( “jobpostings” )
. limit ( 1000 )
. find ()
. then ( results => {
const uniqueItems = getUniqueItems ( results . items );
$w ( “#countryDropdown” ). options = buildOptions ( uniqueItems );
const uniqueItems2 = getUniqueItemsLoc ( results . items );
$w ( “#companyType” ). options = buildOptions ( uniqueItems2 );
const uniqueItems3 = getUniqueItemsType ( results . items );
$w ( “#employment” ). options = buildOptions ( uniqueItems3 );
});
//---------------------------------------------------------//
function getUniqueItems ( items ) {
const itemsOnly = items . map ( item => item . field );
return [… new Set ( itemsOnly )];
}
function getUniqueItemsLoc ( items ) {
const itemsOnly = items . map ( item => item . location );
return [… new Set ( itemsOnly )];
}
function getUniqueItemsType ( items ) {
const itemsOnly = items . map ( item => item . type );
return [… new Set ( itemsOnly )];
}
function buildOptions ( uniqueList ) {
return uniqueList . map ( curr => {
return { label : curr , value : curr };
});
}
});
// end of jobField dropdown - please work i beg of you
export function input1_keyPress ( event ) {
let SearchValue = $w ( “#input1” ). value ;
$w ( “#dataset1” ). setFilter ( wixData . filter (). contains ( ‘jobTitle’ , SearchValue )
. or ( wixData . filter (). contains ( ‘location’ , SearchValue ))
. or ( wixData . filter (). contains ( ‘field’ , SearchValue )));
}
export function searchButton_click_1 ( event ) {
search ();
}
function search () {
wixData . query ( “jobpostings” )
. contains ( “field” , String ( $w ( “#countryDropdown” ). value ))
. and ( wixData . query ( “jobpostings” ). contains ( “location” , String ( $w ( “#companyType” ). value )))
. and ( wixData . query ( “jobpostings” ). contains ( “type” , String ( $w ( “#employment” ). value )))
. and ( wixData . query ( “jobpostings” ). contains ( “remote” , String ( $w ( “#checkboxGroup1” ). value )))
. find ()
. then ( results => {
$w ( “#repeater4” ). data = results . items ;
});
}
// =============================================//
$w . onReady (() => {
$w ( ‘#clearButton’ ). onClick (() => {
$w ( “#countryDropdown” ). value = undefined
$w ( “#companyType” ). value = undefined
$w ( “#employment” ). value = undefined
$w ( “#checkboxGroup1” ). value = undefined
$w ( “#dataset1” ). setFilter ( wixData . filter ()
. eq ( ‘field’ , location ))
});
});
Have a lovely day,
-D