twitter / typeahead.js

typeahead.js is a fast and fully-featured autocomplete library
http://twitter.github.io/typeahead.js/
MIT License
16.52k stars 3.21k forks source link

Recharge after new registration #1815

Open ivanteles opened 1 year ago

ivanteles commented 1 year ago

I'm using version 0.9.3 of https://github.com/twitter/typeahead.js/blob/master/doc/jquery_typeahead.md

I have a screen that works perfectly, in the empty template, I add a link that opens a modal to register a new option.

When registering, the user closes the modal, but when making a new call to the field, despite the call to the method, it is occurring correctly and bringing in the existing data and also the new data that has just been registered.

The plugin displays an empty list.

var carregarDadosComoAddUrlSetValSelectItem = function (campo, url, urlAdd, title, campoSetVal) {
  const dados = new Bloodhound({
        datumTokenizer: Bloodhound.tokenizers.whitespace,
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        sufficient: 1,
        indexRemote: true,
        remote: { wildcard: '%QUERY', url: url + '?q=%QUERY' }
    });
    dados.initialize();
    $(campo).typeahead({ hint: true, highlight: true, minLength: 1 }, {
        display: 'nome',
        source: dados,
        templates: {
            empty: [`<div class='empty-message'><a href='${urlAdd}' class="detalhesPaiPai hand" data-original-title='${title}' title='${title}'>Nenhuma informação encontrado, clique aqui e faça o cadastro</a></div>`].join('\n'),
            suggestion: function (data) { return '<p>' + data.nome + '</p>'; }
        }
    }).bind('typeahead:select', function (ev, item) {
        $(campoSetVal).val(item.id);
    });
}
carregarDadosComoAddUrlSetValSelectItem("#NomeCategoria", "/Categoria/AutoComplete", "/Categoria/Add?tipo=add", "Nova categoria", "#IdCategoria");
ivanteles commented 1 year ago

Any personal tips?