Closed folknor closed 3 years ago
For example a new property on resultsList
like append
and prepend
where we can return HTMLElement
that is always inserted before or after the result elements.
Would probably need to have config for if to add them when results are 0. Would be nice to have that information in resultsList.container
as well.
Hello @folknor,
Good catch!
The issue has been fixed in v9.0.4
Check it and let me know how it goes.
Have a nice day! :)
Thank you it works great! :+1:
I changed my code to also make sure clicking the node doesn't close the list like this
container: element => {
const result = document.createElement("p")
result.setAttribute("class", "no_result")
result.setAttribute("tabindex", "1")
result.innerHTML = `Skriv inn hele organisasjonsnummeret, uten mellomrom.`
result.addEventListener("click", (ev) => { ev.stopPropagation() } )
element.appendChild(result)
},
Glad to hear that! :)
For example a new property on
resultsList
likeappend
andprepend
where we can returnHTMLElement
that is always inserted before or after the result elements.Would probably need to have config for if to add them when results are 0. Would be nice to have that information in
resultsList.container
as well.
Since the element
parameter contains the entire list element you can check it if empty to make conditional changes
Since the
element
parameter contains the entire list element you can check it if empty to make conditional changes
Can you explain how? Because you invoke resultsList.container
before adding the child elements at https://github.com/TarekRaafat/autoComplete.js/blob/master/dist/js/autoComplete.js#L204
I think I am misunderstanding something.
Wait you just changed it :-D
You're right I've just noticed that after my reply and I've just changed it in v9.0.5
Check it and let me know :)
Wait you just changed it :-D
Yes, my bad 😅
Great work thanks again! :100: :+1:
resultsList: {
container: element => {
if (element.children.length === 1 && element.children[0].classList.contains("autoComplete_ingen-resultat")) {
return
}
const result = document.createElement("p")
result.setAttribute("class", "autoComplete_info")
result.setAttribute("tabindex", "-1")
result.innerHTML = `<span class="iconify-inline" data-icon="fa-solid:exclamation-triangle"></span>Du må velge en bedrift fra denne listen. Det er ikke nok å skrive inn navnet eller organisasjonsnummeret.`
result.addEventListener("click", ev => {
ev.stopPropagation()
})
element.prepend(result)
},
maxResults: 8,
idName: "bedrift-liste",
noResults: (list, query) => {
const result = document.createElement("li")
result.setAttribute("class", "autoComplete_ingen-resultat")
let nr = /^\d+$/.test(query)
if (nr === true) {
result.innerHTML = `<span class="iconify-inline" data-icon="fa-solid:exclamation-triangle"></span>Skriv inn hele organisasjonsnummeret, uten mellomrom.`
} else {
result.innerHTML = `<span class="iconify-inline" data-icon="fa-solid:exclamation-triangle"></span>Fant ingen resultat for "${query}".`
}
list.appendChild(result)
}
},
[ ] System Information
[ ] Describe the bug
Here's the code for one of my autocompletes (work in progress)
In
resultsList.container
I add ap
element at the top of the list that I want to use to give helpful information to the user. Here's a screenshot: (the text in thep
is currently wrong, also the element is not styled properly - I just started implementing it, but that's not relevant to the bug)[ ] To Reproduce Steps to reproduce the behavior: <!-- Example below-!>
resultsList.container
[ ] Expected behavior I want the element to be there every time :-)
I think the "problem" is in your function
generateList
you dolist.innerHTML = "";
iflist
is non-null.Perhaps it would be possible to add an attribute to my element that makes autoComplete.js not nuke it?
Or maybe you have an alternative solution for me :-) Thank you!