-
-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple keys: Return matches from both keys? #268
Comments
The only way to accomplish this at the moment is to use the It's also best to avoid using |
Thanks for the fast response! Are you referring do the searchEngine option of passing a function? Do you have any examples of how this works? |
new autoComplete({
searchEngine: (q, r) => {
if ( r.includes(q) ) {
return r
}
return false
}
}) If you don't use new autoComplete({
searchEngine: (q, r) => {
if ( r.surname.includes(q) ) {
return r.surname
}
if ( r.firstname.includes(q) ) {
return r.firstname
}
return false
}
}) |
Hi @folknor , I tried to use searchEngine but when I select an item, the selection is always undefined. any thoughts on it? THis is my codepen - https://codepen.io/viswanathamsantosh/pen/wveBgob |
Hello @devcer, The issue basically within the
autoCompleteJS.input.addEventListener("selection", function (event) {
const feedback = event.detail;
autoCompleteJS.input.blur();
// Prepare User's Selected Value
const selection = feedback.selection.value[feedback.selection.key];
// Render selected choice to selection div
document.querySelector(".selection").innerHTML = selection;
// Replace Input value with the selected value
autoCompleteJS.input.value = selection;
// Console log autoComplete data feedback
console.log(feedback);
});
autoCompleteJS.input.addEventListener("selection", function (event) {
const feedback = event.detail;
autoCompleteJS.input.blur();
// Prepare User's Selected Value
const name = feedback.selection.value.name;
const email = feedback.selection.value.email;
// Render selected choice to selection div
document.querySelector(".selection").innerHTML = `${name} - ${email}`;
// Replace Input value with the selected value
autoCompleteJS.input.value = `${name} - ${email}`;
// Console log autoComplete data feedback
console.log(feedback);
}); Here is the fixed example. I've enhanced your
searchEngine: (q, r) => {
if (r.name.includes(q)) {
return r;
}
if (r.email.includes(q)) {
return r;
}
return false;
},
searchEngine: (q, r) => {
const query = q.toLowerCase();
const name = r.name.toLowerCase();
const email = r.email.toLowerCase();
if (name.includes(query)) {
return r;
}
if (email.includes(query)) {
return r;
}
return false;
}, Let me know how it works. Have a nice day! :) |
@TarekRaafat This works perfect! Thank you so much 😃 |
You're most welcome anytime! :) |
Sorry if I'm misunderstanding the documentation, but it looks to me from testing that if you specify multiple keys it will look for matches in one key or the other but not both. For example:
https://codepen.io/tarekraafat/pen/rNyBxdL
The data contains this:
A search for "wild" will return a result from that row, and a search for "luthu" will return a result from that row, but searching "wild luthu" will not return anything.
I'd like to be able to do a name search by firstname and surname so that a search for "owe leo" would return this row:
Is this currently possible?
The text was updated successfully, but these errors were encountered: