I use the following code to just find and tag friends in a text box, which I then pass to Ajax Post. As you can see in my image, I can only allow users to tag friends one after another. Instead of restricting users to only type friend names for tags, I want to emulate Facebook and Twitter and allow users to enter status updates, and then when they type “@”, they call select2 to call ajax to search for friends. Here is my current code:
$("#tag_friends").select2({ formatResult: peopleFormatResult, formatSelection: peopleFormatSelection, tags: true, tokenSeparators: [",", ""], multiple: true, placeholder: "Tag Your Friends", minimumInputLength:1, ajax: { type: "POST", url: domain+"friendstag", dataType: "json", data: function(term, page) { return { q: term }; }, results: function(data, page) { return { results: data }; } } }); function peopleFormatResult(people) { var html = "<table class='people-resultado'><tr>"; html += "<td class='taggin_image'><img src='"+people.image+"'/></td>"; html += "<td class='people-info'>"; html += people.name + "<br />"; html += "</td></tr></table>"; return html; } function peopleFormatSelection(people) { return people.name; }
I use this in my post ajax after using the selected ids:
var tagged_friends = $("#tag_friends").select2("val");
Here's what it looks like now: 
I worked a week without any success, and I need it to look like this: 
Tagging will be initiated when the user types @. Also, any ideas on how I can capture user IDs after someone has tagged friends?
I hit a steel wall. Any help would be greatly appreciated.
Thanks.
javascript jquery jquery-select2
user1011713
source share