Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 with Bootstrap Tags Input and typeahead don't show the tags inside input

I'm trying to use Bootstrap 3 with Bootstrap Tags Input and typeahead but it doesn't show the tags inside the input.

It is difficult to explain... It is better to see in jsfiddle: https://jsfiddle.net/claudiosw/5cww4fcg/3/

I have tried to use typeahead.js but the result was the same.

Here is the code:

<input type="text" class="form-control" rows="3" value="Test1,Test2" data-role="tagsinput" />


<script>
  $(document).ready(function() { 

      $('input').tagsinput({
        typeahead: {
          source: ['Amsterdam', 'Washington', 'Sydney', 'Beijing', 'Cairo']
        }
      });
  });
</script>

Thanks in advance!

like image 688
Claudio Shigueo Watanabe Avatar asked Apr 07 '17 13:04

Claudio Shigueo Watanabe


1 Answers

To fix it do two things:

  1. To show the tags inside the input dont use both data-role="tagsinput" and tagsinput(). Instead, init it only with in the js.
  2. To clear the plaintext after a tag is added you should add:

    afterSelect: function() {
        this.$element[0].value = "";
    }
    

    to the tagsinput() options.

See updated JSFiddle

like image 142
Jaqen H'ghar Avatar answered Oct 19 '22 18:10

Jaqen H'ghar