LeaVerou / awesomplete

Ultra lightweight, usable, beautiful autocomplete with zero dependencies.
http://leaverou.github.io/awesomplete/
MIT License
6.97k stars 611 forks source link

Is it possible to search not only by label? I want to search also to value or other fields #17220

Open kritsky opened 4 years ago

kritsky commented 4 years ago

new Awesomplete(input, { list: [ { label: "Belarus", value: "BY" }, { label: "China", value: "CN" }, { label: "United States", value: "US" } ] });

When I type CN there will be result China

bbenjamin commented 4 years ago

You can do this by customizing the filter. An example in this is in the "Extend" section on https://leaverou.github.io/awesomplete/#extensibility - it is the first item in the table.

The "text" function arg is typically treated as a string with the suggestion label, but it actually an object that provides both the label and value in text.label and text.value. Update the filter function to check both text.label and text.value instead of just text and you'll get the functionality you're looking for!

If this answers your question successfully, please close the issue or I'll close after a week of inactivity.