Page 1 of 1

Get name in fbautocomplete jquery plugin

Posted: 28 Oct 2018, 14:30
by JanMolendijk
I`m almost their with my tag-system

But my second question for today: I can`t find-out how to detect the names from this javascript.
I can detect the id " + itemId + " this is working normal

in this part it detect the names
add2Advanced("Current selected users: " + itemId + " " + titles.join(", "));

But I can not find out what to do to detect the names like I can detect the id.

Code: Select all

<script type="text/javascript">
$(function(){
/*
*
Simple
*
*/
$('#fbautocomplete_id').fbautocomplete();


/*
*
Advanced
*
*/
$('#fbautocomplete_id_advanced').fbautocomplete({
url: 'friends.php', // which url will provide json!

maxItems: 0, // only one item can be selected
// do not use caching, always calls server even for something you have already typed. 
// Probably you want to leave this on true
useCache: true, 
onItemSelected : function($obj, itemId, selected) {
  if (selected) {
    add2Advanced("User with id = <a href='/Jan-Molendijk/Member-Profile.php?id=" + itemId + "' title='' class='postlink' target='hoofd'>" + itemId + "</a> has been added");
    var titles = [];
    for (var i in selected) titles[i] = selected[i].title;
    add2Advanced("Current selected users: " + itemId + " " + titles.join(",  "));
  } 
},
onItemRemoved : function($obj, itemId) {
  add2Advanced('User with id = ' + itemId + ' has been removed');
},
onAlreadySelected: function($obj) {
  add2Advanced('That user is already selected'); 
}
});

function add2Advanced(str) {
$('#advanced_actions').html($('#advanced_actions').html() + '<br />' + str);

}
});	
</script>

Get name in fbautocomplete jquery plugin

Posted: 28 Oct 2018, 19:23
by Admin
I not know how that jquery plugin works.
In the function from onItemSelected apply the following code to see in browser console what data is in the $obj and selected parameters.
Maybe the name can be found in their values.

Code: Select all

console.log($obj);
console.log($selected);

Get name in fbautocomplete jquery plugin

Posted: 29 Oct 2018, 19:47
by JanMolendijk
Thanks for supporting but I still dont understand where to place the console.log ?

Something like this ?

Code: Select all

onItemSelected : function($obj, itemId, selected) {
  if (selected) {
  console.log($obj);
console.log($selected);
  }
  }
  

Get name in fbautocomplete jquery plugin

Posted: 30 Oct 2018, 08:02
by Admin
Yes, in that function.
Then, see in browser console (F12) what data is displayed.