I have a situation where I need to focus on input/textarea/contenteditable elements. Then set the values programmatically. After that I need to emulate tab or enter programmatically so that entered text can look like tags as show in below picture.
can anybody suggest how can this be achieved?
Just like below demo, I have a input field. I have added blur for the demonstration purpose but I want tab or enter events to be fired. I know that blur will do the trick but I dont want that.
Demo: http://jsfiddle.net/2np1cwe6/ Vanilla JS code: http://jsfiddle.net/dyc4bLta/
$('input').tagsinput({
typeahead: {
source: ['Amsterdam', 'Washington', 'Sydney', 'Beijing', 'Cairo']
},
freeInput: true
});
$('input').on('itemAdded', function(event) {
setTimeout(function(){
$(">input[type=text]",".bootstrap-tagsinput").val("");
}, 1);
});
var i = $('input');
setTimeout(function() {
i.focus()
i.val('adfasdfasd');
}, 2000);
setTimeout(function() {
i.blur()
}, 8000);