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
feature request, multi key for search in object #21
Comments
Hello @Johann-S, Thank you very much, I'm glad you like it! Your point is totally clear, and I was actually considering implementing multiple Currently you can use multiple resultItem: (data, source) => {
return `${data.source.food} from ${data.source.city}`;
}, Hope this would be a little helpful for you for the time being until multiple Thank you for your valuable suggestion, have a good day! :) |
Hello @Johann-S , Check out v4.0.0 or CDN it's just released and it supports Let me know your feedback. Cheers! :) |
Oh awesome ! thank you ❤️ Edit: it works perfectly ! |
Is it possible to display both results on the same line and both to have the match highlighted?
This will just display them side by side separated with dash but will not highlight them |
Hello @krispetkov, Sorry for my late reply. In order to achieve such a result, you'll need to get the user's query to be compared against the matching result string and highlight it as shown in the below code snippet. resultItem: {
content: (data, source) => {
// Get query vallue
let query = document.querySelector("#autoComplete").value;
// Build desired result string
const result = `${data.value.food} - ${data.value.cities}`;
// Regular Expression Query Pattern Ignores caseSensitive
const pattern = new RegExp(`${query}`, "i");
// Search for a match Query in Record
query = pattern.exec(result);
// Returns the highlighted match
source.innerHTML = result.replace(query, `<span style="color: red;">${query}</span>`);
},
element: "li"
} Please try it and let me know the results. Stay safe, cheers! :) |
@TarekRaafat Thank you! great answer! One more question? Is it possible to make the engine to color more than one word? Example (from your previous answer): |
I was looking to solve this problem by looking the issues. I think the API changed, right? So instead of
We have to use:
At least like the last one I could modify the element, the other option didn't work anymore. |
Thanks @kasperkamperman, for your helpful comment! :)
Would you please clarify which option you are referring to? |
I meant that "content: (data, source)" like mentioned in this topic didn't work anymore. So the full-code you showed in this topic would become in the most recent version (10.2.5) that I'm using:
@TarekRaafat Thanks for the script and helpful replies. |
Just a slight correction resultItem: {
// For element tag type use `tag` instead of `element`
tag: "li",
// For the element itself use `element` instead of `content`
element: (item, data) => {
// Get query value
let query = document.querySelector("#autoComplete").value;
// Build desired result string
const result = `${data.value.food} - ${data.value.cities}`;
// Regular Expression Query Pattern Ignores caseSensitive
const pattern = new RegExp(`${query}`, "i");
// Search for a match Query in Record
query = pattern.exec(result);
// Returns the highlighted match
item.innerHTML = result.replace(query, `<span style="color: red;">${query}</span>`);
}
} Cheers, and have a nice day! :) |
I needed something like this for both name and email search. I had to use replaceAll instead to highlight both email and name.
Is there anyway I could replace text but not the case? Example |
Hi,
Thanks for that awesome plugin !
I would like to know what do you think about adding multi
key
s when we use an array of Objects.For example:
and key would be:
[ 'label', 'code' ]
I'm sorry if it's not clear but do not hesitate to ask me more details
The text was updated successfully, but these errors were encountered: