tag-it icon indicating copy to clipboard operation
tag-it copied to clipboard

Is it possible to make tags values different than labels?

Open Harry180 opened this issue 10 years ago • 11 comments

@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.

Harry180 avatar Jun 02 '14 16:06 Harry180

I'm also very much interested in this use case!

aolieman avatar Jun 15 '14 14:06 aolieman

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.

swemoney avatar Jun 24 '14 15:06 swemoney

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.

PawelRoman avatar Sep 30 '14 18:09 PawelRoman

+1

mhuggins avatar Jan 26 '15 02:01 mhuggins

+1

codingCookie avatar Feb 10 '15 20:02 codingCookie

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 avatar Feb 19 '15 17:02 CodingBeard

@CodingBeard Doesn't this add the tag twice? Once when tagit adds it and once on afterTagAdded ?

dmill-bz avatar Apr 21 '15 19:04 dmill-bz

@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.

CodingBeard avatar Apr 21 '15 21:04 CodingBeard

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.

samwilson avatar Sep 02 '15 06:09 samwilson

$('#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?

fenfenyan avatar Mar 20 '17 09:03 fenfenyan

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?

krishna1682 avatar Feb 23 '18 14:02 krishna1682