Code a Multi-Search

Ok, I am clearly getting bold in my old age.

I have mastered the Single Field Search => Table and the Single Field Search => Individual Text Fields.

Now, what I would like to tackle is a situation where someone could input, say 5 ailments that they currently have (each housed in its own user-input box), and with the click of one button, have the results delivered to customized text fields.

I am practicing with 2 user input boxes, the output boxes, and the search button. I wrote the code based on what you guys had previously instructed me in, but I am getting one error message on the very last line that says “Unexpected token.” There is only a bracket on the last line.

Here is the code that I used:

import wixData from ‘wix-data’;

//For full API documentation, including code examples visit http://wix.to/94BuAAs

$w.onReady(function () {
//TODO: import wixData from ‘wix-data’;
});

export function searchButton_onClick(event) {
//this would be from the first search field
wixData.query(‘Members-BodyLanguage’)
.contains(‘title’, $w(‘#searchByCondition’).value)
.find()
.then( res => {
//this is where you make the changes
$w(‘#bodyLangTitle’).text = res.items[0].title;
$w(“#bodyLangDescr”).html = res.items[0].meaningNew;
$w(“#bodyLangAntedote”).html = res.items[0].antedote;
//this would be from the second search field
wixData.query(‘Members-BodyLanguage’)
.contains(‘title’, $w(‘#searchByCondition2’).value)
.find()
.then( res => {
//this is where you make the changes
$w(‘#bodyLangTitle2’).text = res.items[0].title;
$w(“#bodyLangDescr2”).html = res.items[0].meaningNew;
$w(“#bodyLangAntedote2”).html = res.items[0].antedote;
});
}

What is the purpose of searching for the same from two boxes against the same collection? Can’t you runt two contains after each other?

But anyway you are missing the closure from the first then?

$w.onReady(function () {
	//TODO: import wixData from 'wix-data';
});
export function searchButton_onClick(event) {
//this would be from the first search field 
 wixData.query('Members-BodyLanguage')
 .contains('title', $w('#searchByCondition').value)
 .find()
 .then( res => {
   //this is where you make the changes
   $w('#bodyLangTitle').text = res.items[0].title;
   $w("#bodyLangDescr").html = res.items[0].meaningNew;
   $w("#bodyLangAntedote").html = res.items[0].antedote;
//this would be from the second search field
  wixData.query('Members-BodyLanguage')
  .contains('title', $w('#searchByCondition2').value)
  .find()
  .then( res => {
   //this is where you make the changes
   $w('#bodyLangTitle2').text = res.items[0].title;
   $w("#bodyLangDescr2").html = res.items[0].meaningNew;
   $w("#bodyLangAntedote2").html = res.items[0].antedote;
}); // First then opener 
}); // Second then opener
} // Function closure

I hope you get it and try adding the last closure to the code. Unexpected token often mean that something is not closed properly using brackets, curly braces and so on.

I figured it was something like that. I will try it and see if I can get it to work. The reason for the multiple search fields is so my clients can enter multiple ailments they suffer from and look up those meanings all at one time.