Guest User

Untitled

a guest
Jul 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. //function to auto complete in text box under "ADD" tab
  2. //This allows a user to input as many friends as he wishes
  3. function fillAutoComplete(friends_list) {
  4. $('input#opponents').autocomplete({
  5. source: $.map(friendList, function(item) {
  6. return {
  7. label: item.name,
  8. value: item.name,
  9. id: item.id
  10. }
  11. }),
  12. focus: function() {return false},
  13. multiple: true,
  14. select: function(event, ui) {
  15. var terms = (this.value).split(/,\s*/);
  16. terms.pop();
  17. terms.push(ui.item.value);
  18. terms.push("");
  19. this.value = terms.join(", ");
  20. var temp = $('input#oppID').val();
  21. if(temp != "") {
  22. $('input#oppID').val(temp + "," + ui.item.id);
  23. } else {
  24. $('input#oppID').val(ui.item.id);
  25. }
  26. return false;
  27. }
  28. });
  29. }
  30.  
  31. //These two are needed for autocomplete. Allow for multiple values
  32. function split(val) { return val.split(/,\s*/);}
  33. function extractLast(term) { return split(term).pop();}
Add Comment
Please, Sign In to add comment