Skip to content

How to run tag-it and get the suggested values on button click? #423

@markusrempfer

Description

@markusrempfer

How to run tag-it and get the suggested values on button click?

Here is a fiddle: http://jsfiddle.net/rzL7uvpq/1/. I would like to get the suggested dropdown after button click.

<input id="input-newsearch">
<button class="btn btn-default btn-newsearch" id="search-newsearch" data-toggle="tooltip">Button</button>
$(document).ready(function () {
  $("#input-newsearch").tagit({
    singleField: true,
    singleFieldDelimiter: ",",
    allowSpaces: true,
    autocomplete: ({
    source: function( request, response ) {
        response ( [ { 
            id: '56',
             label: 'Name 01'
             },
         { id: '68',
             label: 'Name 02'
             },
         { id: '49',
             label: 'Name 03'
         },
         { id: '40',
             label: 'Name 04'
          } ] 
         );
      },
        minLength: 3,
        focus: function() {
            return false;
        },
        html: true,
        create: function(item) {
            $(this).data('ui-autocomplete')._renderItem  = function (ul, item) {
                return $( "<li>" )
                    .append( "<a class='newsearch-label'>"+item.label+"</a>" )
                    .appendTo( ul );
            };
            $(this).data('ui-autocomplete')._renderMenu = function( ul, items ) {
                var that = this;
                $.each( items, function( index, item ) {
                    that._renderItemData( ul, item );
                });
            };
        }
    })
});

 $(document).on('click','.btn-newsearch', function() { 
   console.log('Test'); 
   //$('#input-newsearch').trigger("blur"); 
   //$('#input-newsearch').trigger("click"); 
   $('#input-newsearch').trigger("focus"); 
   //$('#input-newsearch').autocomplete('search'); 
   //$('#input-newsearch').autocomplete("search", ""); 
 });  

}); 

What am I missing?

SO: https://stackoverflow.com/questions/57513734/js-jquery-run-tag-it-on-button-click-not-working

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions