Search function by button

i am building a property search page, which i first copied the example giving in one of the wix videos. but as i am changing it with a button click instead of automatically i get in couple of issues
1- price is set as string and i want it as integer (number), thus how can i change it!
2- the search should be an advance one so it should be option 1 or / and option 2 and so on

please check the following code

import wixData from 'wix-data';
$w.onReady(function ()
{
 //TODO: write your page related code here...
});
let lastFilterSearch;
let lastFilterPrice;
let lastFilterPropertyType;
let lastFilterPropertyCat;
let lastFilterPropertyFunction;

export function buttonSearch_click(search, type, price, cat, functionp, $w) {
 //Add your code for this event here: 
 if (lastFilterSearch !== search || lastFilterPropertyType !== type || lastFilterPrice !== price || lastFilterPropertyCat !== cat || lastFilterPropertyFunction !== functionp) 
    {
 let newFilter = wixData.filter();
 if (search)
            newFilter = newFilter.contains('propertyName', search);
 if (type)
            newFilter = newFilter.contains('propertyType', type);
 if (price)
            newFilter = newFilter.le('price', price);
 if (cat)
            newFilter = newFilter.contains('propertyCat', cat);
 if (functionp)
            newFilter = newFilter.contains('propertyFunction', functionp);
         $w('#dataset1').setFilter(newFilter);   
        lastFilterSearch= search; 
        lastFilterPropertyType = type;
        lastFilterPrice = price;
        lastFilterPropertyCat = cat;
        lastFilterPropertyFunction = functionp;
    }
}
export function iSearch_keyPress(event, $w) 
{
    buttonSearch_click($w('#iSearch').value, lastFilterSearch); 
}

export function iType_change(event) {
 //Add your code for this event here: 
    buttonSearch_click($w('#iType').value, lastFilterPropertyType);
}

export function iPrice_keyPress(number, $w) {
 //Add your code for this event here: 
    buttonSearch_click($w('#iPrice').value, lastFilterPrice);
}

export function iFunction_change(event) {
 //Add your code for this event here: 
    buttonSearch_click($w('#iFunction').value, lastFilterPropertyFunction);
}

export function iCat_change(event) {
 //Add your code for this event here: 
    buttonSearch_click($w('#iCat').value, lastFilterPropertyCat);
}

Hello,

For your first question you can do this to change a string to an integer

 const string = '11';
 const newInteger = parseInt(string); 
 console.log(newInteger, typeof newInteger); //  11, number

Regarding your second question, can you be a bit more clear as to what option 1 and option 2 are?

Best,
Majd

hello Majd,

my second question was about the pasted code … it did not work !

regards
Ahmed

any help :frowning:

also found the issue with
export function buttonSearch_click(search, type, price, cat, functionp, $w) << fixed it by taking $w out

however, still got the issue of search
1- when selecting multiple data to search for
2- cannot clear the drop down

also for converting string to integer (as what i had understood ) i did the following
i had changed lastFilterPrice from let to var

var lastFilterPrice; 

and the iPrice to

export function iPrice_keyPress(Number, $w) 
{   
    buttonSearch_click($w('#iPrice').value, parseInt(lastFilterPrice));
}

but as the code is not working i still need help :S

Hay Ahmed,

Your code seems to be a bit confused. You wrote basically (I am leaving out the non relevant parts) something like

export function buttonSearch_click(search, type, price, cat, functionp, $w) {
   ...
}
export function iSearch_keyPress(event, $w) 
{
    buttonSearch_click($w('#iSearch').value, lastFilterSearch); 
}

export function iType_change(event) {
 //Add your code for this event here: 
    buttonSearch_click($w('#iType').value, lastFilterPropertyType);
}

export function iPrice_keyPress(number, $w) {
 //Add your code for this event here: 
    buttonSearch_click($w('#iPrice').value, lastFilterPrice);
}

export function iFunction_change(event) {
 //Add your code for this event here: 
    buttonSearch_click($w('#iFunction').value, lastFilterPropertyFunction);
}

export function iCat_change(event) {
 //Add your code for this event here: 
    buttonSearch_click($w('#iCat').value, lastFilterPropertyCat);
}

You are basically sending the lastXXX params from each of the event handlers as the second parameter of buttonSearch_click, as the type parameter. The result is that you do not pass the parameters right into the function and therefore do not get the search as you expect it to be.

okay

what about this

export function Search_click(event, $w) {
 //Add your code for this event here: 
    $w('#dataset1').setFilter(wixData.filter()
    .contains("propertyCat", $w('#iCat').value)
    .contains("propertyFunction", $w('#iFunction').value)
    .contains("propertyType", $w('#iType').value)
    .contains("price", $w('#iPrice').value)
    .eq("avaliability", true)
    );
    console.info($w('#iCat').value);
    console.info( $w('#iPrice').value);
    console.info( $w('#iFunction').value);
    console.info( $w('#iType').value);
}

it did not work as well :frowning:

Any help please !!