tag-it
tag-it copied to clipboard
Is it possible to make tags values different than labels?
@aehlke Like in title: From server will get autocomplete items like this: { tagName: "some name", tagValue: 1} I would like to show user only tagName but when he/she submit form with this tag-it control it would be great to get this tagValues instead of tagName.
Thanks for answer.
I'm also very much interested in this use case!
I'll put my hand in the ring for this functionality. Would be pretty nice to display a "Real Name" with spaces to the user but use a slug as the tag sent to the server.
Bumping it up! TagIt is great but it completely ignores the fact that autocomplete allows returning items using format [ { label: "Choice1", value: "value1" }, ... ]
TagIt completely ignores label parameter and uses value for both value AND label.
+1
+1
This can be accomplished quite easily without any modification (though less clean than a native function):
var tagValues = {"Tim Doe":"1","Zoe Form":"14","Matthew Potter":"15","Mel Broadwell":"16","Amy Mountain":"19"};
var tagLabels = ["Tim Doe","Zoe Form","Matthew Potter","Mel Broadwell","Amy Mountain"];
$('#tagit').tagit({
availableTags: tagLabels,
beforeTagAdded: function (event, ui) {
if ($.inArray(ui.tagLabel, tagLabels) === -1) {
return false;
}
},
afterTagAdded: function (event, ui) {
$(this).append('<input type="hidden" value="' + tagValues[ui.tagLabel] + '" name="userIDs[]" class="userIDs">');
},
afterTagRemoved: function (event, ui) {
$('.userIDs[value="' + tagValues[ui.tagLabel] + '"]').remove();
}
});
Hope you find that helpful.
@CodingBeard Doesn't this add the tag twice? Once when tagit adds it and once on afterTagAdded
?
@PommeVerte yes, but you can completely ignore tagit's one or not set it at all. It's only the name we explicitly set (userIDs) that will be populated correctly.
There are quite a few issues in the queue about this topic. It'd be a good step to unify them; is this project still maintained? It's been quite a while since the last commit.
$('#cc_to').tagit({
// availableTags: somedates,
autocomplete:{
scroll: true,
scrollHeight: 50, //提示的高度,溢出显示滚动条
max: 10,
source: function( request, response ) {
$.ajax({
type:"post",
url: url,
dataType: "json",
data:{
'q': request.term
},
success: function( data ) {
response( $.map( data, function( item ) {
return {
label:item.chineseName+" "+item.userName+"<"+item.email+">",
value:item.userName
}
}));
}
});
}
},
singleField: true,
singleFieldNode: $('#cc_to'),
allowDuplicates:true,
allowSpaces:true,
removeConfirmation: true,
});
the label shows the whole data got from server, the value appears in the input box. Is this answer helpful?
I am also looking for tags format for my labels in display mode as well. Because when I edit the text and goes back to display mode it is displaying in comma sepated values where I want to see either in space separated or tag format. Can anyone help me on this?