Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
Autocomplete.js paste doesn't show my list of data

This is my code for autocomplete.js (Vanilla). When I paste a word which doesn't match my key for exemple I search for a reference

AP15305-1552

If I do a console.log(data) it returns me my array with my search result. When I check it doesn't go on resultItem.element, I guess it's because the search doesn't match the key event if I have a data.

This is the key if u want to see it

C15305 - 1552 CustomerName.

Someone have any solutions for that ?

<div class="autoComplete_wrapper" style="position : relative">
    <input id="autoComplete" type="search" dir="ltr" spellcheck=false autocorrect="off" autocomplete="off" autocapitalize="off">
</div>
<script>
    var urlrecherche = 'url' ;
    const autoCompleteJS = new autoComplete({
        data: {
            src: async (query) => {
                var url ="webservice/anonymous_PS.asmx/GetJSON?PSname=" + urlrecherche + "&filtre=" ;
                try {
                    // Fetch Data from external Source
                    const source = await fetch(`${url}${query}`);
                    // Data is array of `Objects` | `Strings`
                    const data = await source.json();
                    return data;
                } catch (error) {
                    return error;
                }
            },
            keys: ["Nom"],
            cache: false
        },
        resultItem: {
            element: (item, data) => {
                item.innerHTML = `<a style="color:#337ab7" href="${data.value.Url}">${data.match}<br><small style="color:gray;">${data.value.object}</small></a>`
            }
        },
        events: {
            input: {
                focus() {
                    if (autoCompleteJS.input.value.length) {
                        autoCompleteJS.start()
                    }
                }
            }
        }
    });
</script>

UPDATE

I add this code before return data in data.src

for (let i = 0; i < data.length; i++) {
    if (!data[i].Nom.includes(query) && data.length > 0) {
        var ul = document.getElementById("autoComplete_list_1")
        ul.innerHTML = `<li role="option" id="autoComplete_result_${i}"><a style="color:#337ab7" href="${data[i].Url}">${data[i].Nom}<br><small style="color:gray;">${data[i].objet}</small></a></li>`
    }
}

It doesn't work, it doesn't add my list in the ul and show it

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda