Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bind Bootstrap Tags to dynamically created elements?

I'm having problems binding Bootstrap Tags to an input field an I think its because input field is dynamically created with ajax. Simply nothing is firing.

echo " <div class='tags-cont'>
    <input value='".$tags."' class='tags' type='text' name='tags' data-role='tagsinput' placeholder='Add tags' />
</div>";

Scrtipts are embeded before body closing tag:

<script src='scripts/plugins/bootstrap_tags/bootstrap-tagsinput.js' type='text/javascript'></script>
<link href='scripts/plugins/bootstrap_tags/bootstrap-tagsinput.css' rel='stylesheet' type='text/css' />
like image 654
Munez NS Avatar asked May 08 '26 00:05

Munez NS


1 Answers

I got it. For anyone who will stumble on this in the future:

Remove:

data-role="tagsinput"

And instantiate tagsinput on ajaxComplete:

$(document).ajaxComplete(function(){
        $('.tags').tagsinput({
            maxTags: 3
        });
    });
like image 73
Munez NS Avatar answered May 10 '26 14:05

Munez NS