Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TagIt get value

Tags:

jquery

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

})

1 Answers

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.

like image 159
Dagojvg Avatar answered Feb 03 '26 07:02

Dagojvg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!