$(function () {
var availableTags = [
"A 1 Object ", "A 2 Object ", "B Object ", "C Object ", "D Object ", "E Object ", "F Object ", "G Object ", "H Object ", "I Object "];
function split( val ){
return val.split( /,\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
}
autcomplet_func = {
minLength: 0,
source: function (request, response) {
// delegate back to autocomplete, but extract the last term
response($.ui.autocomplete.filter(
availableTags, extractLast(request.term)));
},
focus: function () {
// prevent value inserted on focus
return false;
},
select: function (event, ui) {
var terms = split(this.value);
// remove the current input
terms.pop();
// add the selected item
terms.push(ui.item.value);
// add placeholder to get the comma-and-space at the end
terms.push("");
this.value = terms.join(", ");
return false;
}
};
$(".tags").bind("keydown",function (event) {
// don't navigate away from the field on tab when selecting an item
if (event.keyCode === $.ui.keyCode.TAB && $(this).autocomplete("instance").menu.active) {
event.preventDefault();
}
}).autocomplete(autcomplet_func);
$("#insert-more").click(function () {
var lastRow = $('#mytable tr:last').clone();
$(lastRow).find('input').val('');
$('.tags', lastRow).autocomplete(autcomplet_func);
$('#mytable').append(lastRow);
});
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.