# How do I create search for multiple fields in dataset? 

**URL:** <https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [May 2, 2019, 4:55am UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149 "2019-05-02T04:55:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![it63306](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/it63306/32/11717_2.png) [@it63306](https://forum.wixstudio.com/u/it63306)\
**Post date:** [May 2, 2019, 4:55am UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/1 "2019-05-02T04:55:41Z")

</div>

Hi there,  
Just wondering if anyone could help me finish a page intended to search a dataset for my business’s retailers and their details.  
The page contains an input, search button, repeater and a dataset, and uses this code:

import wixData **from** “wix-data”;

export function button1\_click(event) {  
wixData.query(“Retailers”)  
.contains(“postcode”, $w(“#input1”).value)  
.find()  
.then(res =\> {  
$w(“#repeater1”).data = res.items;  
});  
}

It works well displaying a retailers details in the repeater when their postcode is entered into the input and the button is clicked, but I would like for the search to work with the other fields such as "town’ and “state”.

Also the page is probably not fully functional unless there is a way that I can make it show retailers in the surrounding postcodes of whatever is searched, so any ideas in making that happen are appreciated.

And ideally but not necessary it would be good if the search button could be clicked using the enter key, and incomplete searches still displayed results.

If anyone is able to give me a hand doing these things it would be greatly appreciated.  
Thankyou 🙂

---

<div class="post-metadata">

**Author:** ![abergquist](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@abergquist](https://forum.wixstudio.com/u/abergquist)\
**Post date:** [May 2, 2019, 5:09am UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/2 "2019-05-02T05:09:43Z")

</div>

Hi, [Forest IT](https://forums.wixapps.net/community-discussion/how-do-i-create-search-for-multiple-fields-in-dataset?cacheKiller=1556772983083&compId=TPASection_jt5yzo1g&currency=ILS&deviceType=desktop&height=626&instance=2mwJlqvE53eiX-tDlAQRLfHf4UGTJgkredeS_Y2Rb40.eyJpbnN0YW5jZUlkIjoiMjViODlmMmItM2JmYy00NmNiLTg5NzgtODJiNGMwYTEyN2U3IiwiYXBwRGVmSWQiOiIxNDcyNGYzNS02Nzk0LWNkMWEtMDI0NC0yNWZkMTM4ZjkyNDIiLCJtZXRhU2l0ZUlkIjoiNWUwNjY5MzgtMmJlZS00OWViLWIzNTEtZDkzYTQ0YmNhNmNjIiwic2lnbkRhdGUiOiIyMDE5LTA1LTAyVDA0OjU5OjU3LjQxNVoiLCJ1aWQiOiI0NGI5MTgxYy1iZjIwLTQ3MmUtODg1NS1lZGUyYjAzZWVjNjgiLCJwZXJtaXNzaW9ucyI6bnVsbCwiaXBBbmRQb3J0IjoiOTkuNDYuOTAuMTA1Lzg2MjIiLCJ2ZW5kb3JQcm9kdWN0SWQiOm51bGwsImRlbW9Nb2RlIjpmYWxzZSwiYWlkIjoiZDlmN2NmNzUtMWFkMi00MThhLTljMDQtZDUyZDcyNTVhZDliIiwiYmlUb2tlbiI6IjdiYmVmNjEzLTEwMTItMGYyMC0zYTI5LTViOGU4NDFkODEyYiIsInNpdGVPd25lcklkIjoiMzc1ODgyM2MtZWFmMy00Njk0LTljMDktY2I3MGY5NTk3ZWMzIiwiZXhwaXJhdGlvbkRhdGUiOiIyMDE5LTA1LTAyVDA4OjU5OjU3LjQxNloifQ&locale=en&pageId=boke6&section-url=https%3A%2F%2Fwww.wix.com%2Fcorvid%2Fforum%2F&siteRevision=4056&target=_top&viewMode=site&vsi=1bdb78ae-1b01-42c0-9009-23ecbc7faf1e&width=1115#) .

1. I would first recommend renaming " [input1](https://www.wix.com/corvid/forum/search/posts%3Fquery=.num.nput1) " to something more mnemonic like " [inputPostCode](https://www.wix.com/corvid/forum/search/posts%3Fquery=.num.nput1) ":

```javascript
wixData.query("Retailers")
  .contains("postcode", $w("#inputPostCode").value)
  .find()
  .then(res => {
    $w("#repeater1").data = res.items;
  }); 

```

1. Does then replacing the above with the following:

```javascript
wixData.query("Retailers")
  .contains("postcode", $w("#inputPostCode").value)
  .and(
    wixData.query("Retailers")
      .contains("town", $w("#inputTown").value)
  )
  .and(
    wixData.query("Retailers")
      .contains("state", $w("#inputState").value)
  )
  .find()
  .then(res => {
    $w("#repeater1").data = res.items;
  }); 

```

take care of “town” and “state” for you? (Alternatively, you might have to replace both occurrences of “.and(” above with “.or(”.)

---

<div class="post-metadata">

**Author:** ![it63306](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/it63306/32/11717_2.png) [@it63306](https://forum.wixstudio.com/u/it63306)\
**Post date:** [May 2, 2019, 5:15am UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/3 "2019-05-02T05:15:36Z")

</div>

Hi @abergquist ,  
Thank you for your quick reply.  
I probably didn’t word correctly that I want to be able to search multiple fields using the same input. If I am unable to do so I may have to use your suggestion.

---

<div class="post-metadata">

**Author:** ![abergquist](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@abergquist](https://forum.wixstudio.com/u/abergquist)\
**Post date:** [May 2, 2019, 1:56pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/4 "2019-05-02T13:56:50Z")

</div>

Hi,

In that case …

1. I would first recommend renaming " [input1](https://www.wix.com/corvid/forum/search/posts%3Fquery=.num.nput1) " to something more mnemonic and more generic like " [inputPostCodeTownOrState](https://www.wix.com/corvid/forum/search/posts%3Fquery=.num.nput1) ":

2. Would the following then work for you:

```javascript
wixData.query("Retailers")
  .contains("postcode", $w("#inputPostCodeTownOrState").value)
  .or(
    wixData.query("Retailers")
      .contains("town", $w("#inputPostCodeTownOrState").value)
  )
  .or(
    wixData.query("Retailers")
      .contains("state", $w("#inputPostCodeTownOrState").value)
  )
  .find()
  .then(res => {
    $w("#repeater1"#repeater1").data = res.items;
  }); 

```

?

---

<div class="post-metadata">

**Author:** ![abergquist](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@abergquist](https://forum.wixstudio.com/u/abergquist)\
**Post date:** [May 2, 2019, 1:58pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/5 "2019-05-02T13:58:02Z")

</div>

When I clicked on [Publish] above, it included an extra (2nd) occurrence of " [#inputPostCodeTownOrState](https://www.wix.com/corvid/forum/search/posts%3Fquery=.num.nput1) " within the double quotes (make sure you have only one/1 occurrence …).

---

<div class="post-metadata">

**Author:** ![it63306](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/it63306/32/11717_2.png) [@it63306](https://forum.wixstudio.com/u/it63306)\
**Post date:** [May 2, 2019, 11:41pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/6 "2019-05-02T23:41:14Z")

</div>

Thank you. For whatever reason it works with “postcode” and “state” but “town” produces no results. I thought it to be an error in the field name or that my input didn’t match any results, but I was thorough in making sure that wasn’t the case and still couldn’t make it work.

---

<div class="post-metadata">

**Author:** ![it63306](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/it63306/32/11717_2.png) [@it63306](https://forum.wixstudio.com/u/it63306)\
**Post date:** [May 2, 2019, 11:44pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/7 "2019-05-02T23:44:29Z")

</div>

Sorry, I was using the field name rather than the field key. Thank you for all your help it is much appreciated.

---

<div class="post-metadata">

**Author:** ![abergquist](https://avatars.discourse-cdn.com/v4/letter/a/c6cbf5/32.png) [@abergquist](https://forum.wixstudio.com/u/abergquist)\
**Post date:** [May 2, 2019, 11:55pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/8 "2019-05-02T23:55:27Z")

</div>

You’re welcome; you can now go to town with your code!

---

<div class="post-metadata">

**Author:** ![contact97609](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@contact97609](https://forum.wixstudio.com/u/contact97609)\
**Post date:** [July 27, 2020, 2:17pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/9 "2020-07-27T14:17:14Z")

</div>

I’m trying to do something similar with just a dropdown trying to search across three fields in the database. Here is the code I am using but it’s not pulling from the other fields:

import wixData from “wix-data” ;

// For full API documentation, including code examples, visit [Velo API Reference - Wix.com](https://wix.to/94BuAAs)  
export function dropdown1(event) {

//TODO: write your page related code here…

wixData.query( ‘#dataset1’ )  
.contains( ‘therapy’ , $w( ‘#dropdown1’ ).value)  
.or.contains( ‘therapyType2’ , $w( ‘#dropdown1’ ).value)  
.or.contains( ‘therapyType3’ , $w( ‘#dropdown1’ ).value)  
.find()  
.then(res =\> {  
$w( ‘#repeater1’ )  
});  
}

---

<div class="post-metadata">

**Author:** ![code-queen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-queen/32/696_2.png) [@code-queen](https://forum.wixstudio.com/u/code-queen)\
**Post date:** [July 27, 2020, 2:24pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/10 "2020-07-27T14:24:18Z")

</div>

That is not the correct syntax for or Query.

Look at Wix’s example on their Reference guide:

> **[or - Velo API Reference - Wix.com](https://www.wix.com/velo/reference/wix-data/wixdataquery/or)**
>
> Adds an or condition to the query or filter. The or() function adds an inclusive or condition to a WixDataQuery or WixDataFilter. A query or filter with an or ...

---

<div class="post-metadata">

**Author:** ![contact97609](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@contact97609](https://forum.wixstudio.com/u/contact97609)\
**Post date:** [July 27, 2020, 2:26pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/11 "2020-07-27T14:26:25Z")

</div>

Thanks, this is my first attempt at coding.

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [July 27, 2020, 2:33pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/12 "2020-07-27T14:33:22Z")

</div>

```javascript

function here_FUNKCTION_NAME() {  
wixData.query("Nam_of_YOUR_wished_DATABASE")
  .contains("therapy", $w('#dropdown1').value)
  .or(wixData.query("Nam_of_YOUR_wished_DATABASE")
      .contains("therapyType2", $w('#dropdown1').value)
  )
  .or(wixData.query("Nam_of_YOUR_wished_DATABASE")
      .contains("therapyType3", $w('#dropdown1').value)
  )
  .find()
  .then(res => {
    let items = res.items
   console.log(res)
   console.log (items)
  }); 
}

```

And you will still need a TRIGGER which will call/start this function (for example a press on a button, or a change-event in a dropdown, or what ever.

```javascript
exportfunction dropdown1(event) {here_FUNKCTION_NAME()}

```

And of course you need to import the relevant API… (to the VERY TOP of the CODE)

```javascript
import wixData from"wix-data";

```

I did not test it, but should work theoreticaly.  
You will find the results in CONSOLE in the PREVIEW-MODE or when pressing F-12 in your google-chrome-browser and switching to CONSOLE-section.

EDIT: And by the way, this solution does not use any dataset.

---

<div class="post-metadata">

**Author:** ![code-queen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-queen/32/696_2.png) [@code-queen](https://forum.wixstudio.com/u/code-queen)\
**Post date:** [July 27, 2020, 2:50pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/13 "2020-07-27T14:50:30Z")

</div>

This is already a lot more than a lot of people attempt so keep going 😉

Use the Wix Reference guide when in doubt.  
Take a look at Wix’s examples. I learned by ‘reverse coding’ them. Pulling them apart and redoing them to understand how and why things work a certain way.

You are on the right track so keep going.

---

<div class="post-metadata">

**Author:** ![contact97609](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@contact97609](https://forum.wixstudio.com/u/contact97609)\
**Post date:** [July 27, 2020, 3:19pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/14 "2020-07-27T15:19:31Z")

</div>

Thank you. It is so hard when you’re not sure what part relates to what. This is what I’ve changed it to so far (but still not working):

import wixData from “wix-data” ;

// For full API documentation, including code examples, visit [Velo API Reference - Wix.com](https://wix.to/94BuAAs)  
export function dropdown1(event) {

//TODO: write your page related code here…

wixData.query( “therapies” )  
.contains( ‘therapy’ , $w( ‘#dropdown1’ ).value)  
.or(  
wixData.query( “therapies” )  
.contains( ‘therapyType2’ , $w( ‘#dropdown1’ ).value)  
)  
.or(  
wixData.query( “therapies” )  
.contains( ‘therapyType3’ , $w( ‘#dropdown1’ ).value)  
)  
.find()  
.then(res =\> {  
$w( ‘#repeater1’ )  
});  
}

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [July 27, 2020, 4:30pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/15 "2020-07-27T16:30:29Z")

</div>

Hello one more time.

You probably just forgot something 😁

```javascript
.find()
  .then(res => {
    $w("#repeater1"#repeater1").data = res.items;
  }); 

```

1. You did a query of your DATABASE ? —\> YES
2. You did filter some data ? —\> YES
3. You did let showing you the results ? Not really!

And here we have an error…

```javascript
 .then(res => { $w('#repeater1') });

```

---

<div class="post-metadata">

**Author:** ![contact97609](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@contact97609](https://forum.wixstudio.com/u/contact97609)\
**Post date:** [July 28, 2020, 4:14pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/16 "2020-07-28T16:14:37Z")

</div>

I’ve changed that to $w( “#repeater1” #repeater1 ").data = res.items;  
but it is giving an error of $w should only get one argument

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [July 28, 2020, 4:54pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/17 "2020-07-28T16:54:36Z")

</div>

Ok, we have some ERRORs here. You are not doing exactly what a suggest you.

Try this one…

```javascript
import wixData from"wix-data";

$w.onReady(function(){ }

export function dropdown1_change(event) {xxx()}

function xxx() {
    wixData.query("therapies")    
    .contains('therapy', $w('#dropdown1').value)    
    .or(wixData.query("therapies")
    .contains('therapyType2', $w('#dropdown1').value))    
    .or(wixData.query("therapies")
    .contains('therapyType3', $w('#dropdown1').value))
    .find()
    .then( (results) => {
        console.log(results)
        $w('#repeater1').data = results.items;
    });
}    

```

---

<div class="post-metadata">

**Author:** ![contact97609](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@contact97609](https://forum.wixstudio.com/u/contact97609)\
**Post date:** [July 28, 2020, 5:23pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/18 "2020-07-28T17:23:57Z")

</div>

Thank you, I’m sorry, I’ll get better. What does the xxx parts mean?

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [July 28, 2020, 5:38pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/19 "2020-07-28T17:38:08Z")

</div>

XXX = name of the function. You can name it like you want.  
YYY / ZZZ / myFunction / doMyFilter / start\_FilteringProcess / myFunctionWithoutName as you want 🤣🤣🤣

But if you change it, do not forget to change on both parts …

1. BUTTON-PART

```javascript
export function dropdown1_change(event) {ZZZ()}

```

1. CODE-PART

```javascript
function ZZZ() {

```

---

<div class="post-metadata">

**Author:** ![contact97609](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@contact97609](https://forum.wixstudio.com/u/contact97609)\
**Post date:** [July 28, 2020, 5:40pm UTC](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149/20 "2020-07-28T17:40:14Z")

</div>

I got it. The xxx is the event that needs to be the same in each area. So it can be any name, just as long as they are the same!

[Next page](https://forum.wixstudio.com/t/how-do-i-create-search-for-multiple-fields-in-dataset/21149.md?page=2)
