Edit: Added working JSFiddle
I'm using Twitter Bootstrap TagsInput with Bootstrap Typeahead. My source is a json file, but that is irrelevant, and I've checked with a static source.
The typeahead and tagsinput are working, however when I press enter, tab, or click on a tag, it creates a duplicate complete.
That extre 'default' happens whenever I press enter, or complete the typeahead. If I break the typeahead by separating with comma, or taking focus away from the window, it does not occur.
Here is the input:
<input id="itemCategory" type="text" autocomplete="off" class="tagsInput form-control" name="itemCategory">
And here is the script:
<script>
$('.tagsInput').tagsinput({
confirmKeys: [13, 44],
maxTags: 1,
typeahead: {
source: function(query) {
return $.get('listcategories.php');
}
}
});
</script>
I'm sure it's something wonky that won't be reproducable, with my luck, so I'm hoping someone will have some institutional knowledge that they know would cause something like this to happen.
Here is an image of the extra text, in dev. tools:
I really appreciate any advice or suggestions. Thank you.
WORKING CODE
Thanks to @Girish, the following was what "fixed" this issue. I believe it to be a bug at this point in time, introduced somewhere in a more recent version of jQuery or the Typeahead. This code just manually removes the extra element, although hopefully something will come along to prevent it from being placed there in the first place, eliminating the extra code. For now it works for me.
$('.tagsInput').tagsinput({
confirmKeys: [13, 44],
maxTags: 1,
typeahead: {
source: function(query) {
return $.get('tags.php');
}
}
});
$('.tagsInput').on('itemAdded', function(event) {
setTimeout(function(){
$(">input[type=text]",".bootstrap-tagsinput").val("");
}, 1);
});