Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
markusrempfer opened this issue Aug 16, 2019 · 1 comment
Open

Comments

@markusrempfer
Copy link

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

@vsoch
Copy link

vsoch commented Aug 20, 2020

I'm not a tagit maintainer, but taking a look at your example, the dropdown appears when you start typing. The button isn't needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants