[SOLVED] problem with my search bar code

Hi there,
I’m trying to create search bar with the code below by the Wix video on youtube but for some reason, it’s not working. If you can see the problem please let me know.

import wixData from "wix-data";

export function iTitle_keyPress(event, $w) {
	wixData.query('Novinky'); 
	console.log($w('#iTitle').value);
	filter($w('#iTitle').value);	
}

function filter(title) {
	$w('dataset1').setFilter(wixData.filter().contains('Title', title);
}

YouTube link:

My test site link:
https://kubanjakub91.wixsite.com/goa-test

Thanks,
Jakub

Hi Jakub,
The code in below may give you some helps,

import wixData from 'wix-data'
//...

export function iTitle_keyPress() { 
    var searchValue = $w("#iTitle").value;
    wixData.query("Novinky").eq("propertyInDataBase", searchValue).find().then( (Res)=>{ 
            // if there are items do...
            if ( Res.items.length > 0 ) { 
                 // Table or Repeater items equal to Res.items...
                   //For example,
                       $w("#ThereAreNoItemsText").collapse();
                       $w("#repeater").expand();
                       $w("#repeater").data = Res.items;
            } else { 
            // if there are no items do....
              //For example,
                       $w("#repeater").collapse();
                       $w("#ThereAreNoItemsText").expand();
            }
    } );
}

Hope useful. Good luck,
Heson

Hi Heson,
Thank you for your response. I used your code but I still doing something wrong. Now when I write something to search bar it will only collapse. I will focus on it for a few days and then I will let you know about my progress.

Jakub

I’m still stuck. :confused:

Hi Jakub,

when looking at the - console.log($w(’ #iTitle ').value);
does it print what you expect?
when using the code in the example, specifically ’ propertyInDataBase’ :

wixData.query("Novinky").eq("propertyInDataBase", searchValue)

what column where you meant to search on?

thanks,
Shlomi

Hi Shlomi,
It like I have some typing mistake.
The “propertyInDataBase” may refer to “Title” in Jakub question : )

Hi,
I want to search in “Title” column, si I used Heson code like this:

...
  wixData.query("Novinky").eq("Title", searchValue).find().then( (Res)=>{ 
...
 

When I try Preview mode and write something to search bar then repeater will collapse and Developer Console shows just Loading …

This is my code for now. There will be for shure some mistake I can’t see because I’m still code novice and I just start learning JS.


import wixData from 'wix-data';

export function iTitle_keyPress() { 
    var searchValue = $w("#iTitle").value;
    wixData.query("Novinky").eq("Title", searchValue).find().then( (Res)=>{ 

            if ( Res.items.length > 0 ) { 
 
                       $w("#Title").collapse();
                       $w("#repeater").expand();
                       $w("#repeater").data = Res.items;
            } else { 

                       $w("#repeater").collapse();
                       $w("#Title").expand();
            }
    } );
}

Thanks,
Jakub

Hi Jakub,

The field name for ‘Title’ is most probably ‘title’, all fields start with a lower case letter.
Try wixData.query(“Novinky”).eq(" title ", searchValue)

Hi Ido,
that’s not helping.
I did create Wix profile with 1 site only where I’m trying figure this out.
If I write here Login email and password can you check it out if everything is set well?
This profile was created only for this purpose so I can share it with you guys if you don’t mind and if you would be so nice.

Thanks,
Jakub

Hi Jakub,

No need to share, illI have a look later today

Shlomi

Hi all,

I have a look with the site.
https://kubanjakub91.wixsite.com/goa-test

The repeater is here but the link of the searchInput keypress was gone.

Hi Jackob,

please have a look again, you might find the example below helpful

    $w("#Novinkyds").setFilter( wixData.filter().startsWith("title", $w("#iTitle").value));

good luck,
Shlomi

Thank you guys for your support! This is a good start for the future. =)

Keep working on your dreams,
Jakub