typeahead.js icon indicating copy to clipboard operation
typeahead.js copied to clipboard

Recharge after new registration

Open ivanteles opened this issue 2 years ago • 1 comments

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 avatar Sep 15 '23 14:09 ivanteles

Any personal tips?

ivanteles avatar Sep 28 '23 12:09 ivanteles