Hello, I am relatively new to creating websites using Wix and very new at Wix code.
I have created a dynamic contacts page and have managed to make it search (Søk) for a contact name (Navn) using this code:
import wixData from ‘wix-data’;
//For full API documentation, including code examples visit Velo API Reference - Wix.com
$w.onReady(function () {
//TODO: import wixData from ‘wix-data’;
});
export function button1_click(event) {
wixData.query(‘TCM2018’)
.contains(‘navnKomplett’, $w(‘#input1’).value)
.find()
.then(res => {
$w(‘#table1’).rows = res.items;
});
}
I need help with the code so that it seaches in several fields. I would like to be able to search either by name or by number (Medlemsnr).
Any suggestions or help is greaty appreciated.
Thanks and seasons greetings
Alan
Hi Alan,
To chain a number of queries together, use the following syntax:
wixData.query('test1')
.or(wixData.query('test1').contains('title', $w('#nameInput').value))
.or(wixData.query('test1').gt('age', $w('#numberInput').value))
.or(wixData.query('test1').lt('age', $w('#numberInput').value))
.find()
.then(res => {
console.log(res);
});
}
Hi Ido, thanks very much for reaching out. I have tried to do as you say for a couple of days now but I am quite stuck. Can you say what “age” refers to? Is it the members number field?
Hi Alan,
It refers to the field key in the database collection.
Where did you get stuck ?
Hi Roi and thanks for contacting.
I have a collection of club members and I have it so I can search bt member name and that works. I would like to be able to search either by name or number form the same search box and that is where I am stuck. I tried the syntax provided by Ido (above) but I guess I just do not have any coding knowledge, I think I need to see the complete code and then work on that to see exactly how it works. I have also tried with 2 seach boxes ( one for number and one for name) which would be a heavy handed solution but alas …no go.
See next entry for next image
Hi Roi
I want to search by Navn komplett (name) or Medlemsnr (Number)
My site is www.travellersclub.no and if you apply for membership I can let you in so you can see?
Thanks
Alan