-
-
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
Introduce a new option: data.key_display (defines whose key's value appears in the result list) #334
Comments
Using new autoComplete({
resultItem: {
element: (element, data) => {
if (foo) {
element.innerHTML = `<span>${data.value.foo}</span>`
} else {
element.innerHTML = `<span>${data.value.bar}</span>`
}
}
},
} |
Thank you @folknor ! The only thing this doesn't do yet is getting the
I think this maybe useful for others. Could you include the example somewhere in the documentation, maybe at: https://tarekraafat.github.io/autoComplete.js/#/configuration?id=example-12 |
You can get the query in that function from the const { query, matches, results } = data The highlighted parts won't be lost unless you directly write over |
Thank you for your help! |
Intro
data.keys:
is currently the option which defines the keys that are used to create matches (with thequery
string).But whenever a match happens, the key's value is then also shown as the result in the result list. (The 2 things are linked.)
The issue
What if you have objects with multiple keys, and you want the match to happen in the value of key A, but it's the value of key B that should be displayed in the result list?
Solution
It would thus be great to have a new option
data.key_display:
which would let us define the key whose value should be displayed.Example use case
Being able to search for a city name in various languages, but to always have the English version show up in the result list (not the French name, for example, with which the match was made):
Example:
Type in "Genève" (the French name, used locally in Switzerland) [= value of key A], but have "Geneva, Switzerland" [= value of key B] come up in the result list.
EDIT:
This new option should probably be able to receive multiple keys as well (just like
data.keys:
), thus it could be named:data.keys_display:
The text was updated successfully, but these errors were encountered: