xoxco/jQuery-Tags-Input — pull request #176 by HotspurHN (2014-03-09 16:15:07+00:00)
Title: jquery.aucomplete format + options

Not sure about minificator you use, so before merge, can you minify by
your self?

Usage example: http://puu.sh/7oVAJ.jpg on real project.

var $idPalyersTextArea = $("#id_players");
$idPalyersTextArea.tagsInput({
autocomplete_opt: {
minLength: 2,
select: function (event, ui) {
$idPalyersTextArea.addTag(ui.item.key + ' ' + ui.item.id);
return false;
}
},
autocomplete_url: function (request, response) {
$.when(getResults('player', 'tag', request.term,
'Players')).then(function (resplayers) {
response(resplayers.result);
});
},
defaultText: 'add a player',
delimiter: '\n',
formatAutocomplete: aligulacAutocompleteTemplates
});

var aligulacAutocompleteTemplates = function (ajaxobject) {
if ((!ajaxobject.tag) && (!ajaxobject.name) && (!ajaxobject.fullname)) {
return '' + ajaxobject.label +
'';
}
switch (ajaxobject.objectsType) {
case 'player':
ajaxobject.key = ajaxobject.tag;
return '{aligulac-flag}{aligulac-name}'.replace('{aligulac-flag}',
ajaxobject.country ? '' : ' ')
.replace('{aligulac-race}', aligulacApiConfig.racesDirectory +
ajaxobject.race.toUpperCase() + '.png')
.replace('{aligulac-name}', ajaxobject.tag);
case 'team':
ajaxobject.key = ajaxobject.name;
return '{aligulac-name}'
.replace('{aligulac-name}', ajaxobject.name);
case 'event':
ajaxobject.key = ajaxobject.fullname;
return '{aligulac-name}'
.replace('{aligulac-name}', ajaxobject.fullname);
}
return '' + ajaxobject.value + '';
};