Reputation:
I need get the value from tagit, how can I do that? in afterTagAdded, I call to my controller and I save the object in a List<>, but I don't know how can I get that value. I need send here -->data:{user:here the id}, the value(id), How can I do it?
$('#userNameFriend').tagit({
fieldName: "tags[]",
removeConfirmation: true,
singleField: true,
allowSpaces: true,
placeholderText: 'Name',
tagSource: function ajaxCall(request, response) {
$.ajax({
url: "${pageContext.request.contextPath}/getUserFriends.html",
data: {
term : request.term
},
dataType: "json",
success: function(data) {
response($.map(data.results.list, function(item) {
return{
label:" "+ item.name +" "+item.surname,
value:item.id
};
}));
}
//error: function(error){
//alert("El valor no existe");
//}
});
},
afterTagAdded: function addUser (event,ui){
//Ejecutar llamada al controller para rellenar array con los usuarios elegidos.
//alert("HOLA"+ui.tag.value);
$.ajax({
url:"${pageContext.request.contextPath}/message/fillin.html",
data:{user:here the id},
dataType: "json",
success: function(){
alert("success");
//Append al div de viajes
},
error: function(){
alert("failure"+data);
}
});
}//Adduser
})
Upvotes: 2
Views: 4517
Reputation: 411
If you want to get the tag in the afterTagAdded function. You just need to access the property tagLabel of the ui object, like this: ui.tagLabel
.
If you want to get all the tags that have been added so far. You just need to call the function assignedTags through the tagit object in your input, like this: $('#userNameFriend').tagit('assignedTags')
; this will return an array with the values of the tags.
Upvotes: 11
Reputation:
I use JSP. The user id that I'm trying send is the user selected in that moment. That user has a id that i want to send, and a Name than I show in the input of tagIt. This is the input:
<input id="userNameFriend" name='userNameFriend' type="text" placeholder="Asunto" style="width: 700px;height: 35px"/>
Upvotes: 0