From e4f0cbb222ee39a1d1d21f0d69c39bcc6df9d452 Mon Sep 17 00:00:00 2001 From: sembrestels Date: Wed, 14 Sep 2011 03:21:18 +0200 Subject: Refs #2102. Autocomplete is working now. --- js/lib/autocomplete.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'js/lib') diff --git a/js/lib/autocomplete.js b/js/lib/autocomplete.js index 917326d4f..748070eaa 100644 --- a/js/lib/autocomplete.js +++ b/js/lib/autocomplete.js @@ -5,18 +5,35 @@ elgg.provide('elgg.autocomplete'); elgg.autocomplete.init = function() { $('.elgg-input-autocomplete').autocomplete({ - source: elgg.autocomplete.url, //gets set by input/autocomplete + source: function( request, response ) { + $.ajax({ + url: elgg.autocomplete.url, //gets set by input/autocomplete + dataType: "json", + data: { + q: request.term + }, + success: function( data ) { + response( $.map( data, function( item ) { + item.value = item.name; + return item; + })); + } + }) + }, minLength: 1, select: function(event, ui) { var item = ui.item; - $(this).val(item.name); - - var hidden = $(this).next(); + item.value = item.name; + + if($(this).next().attr('type') == "hidden"){ + var hidden = $(this).next(); + } else { + var hidden = $(this).after('').next(); + } hidden.val(item.guid); } }) - //@todo This seems convoluted .data("autocomplete")._renderItem = function(ul, item) { switch (item.type) { case 'user': @@ -31,9 +48,9 @@ elgg.autocomplete.init = function() { return $("
  • ") .data("item.autocomplete", item) - .append(r) + .append(''+r+'') .appendTo(ul); }; }; -elgg.register_hook_handler('init', 'system', elgg.autocomplete.init); \ No newline at end of file +elgg.register_hook_handler('init', 'system', elgg.autocomplete.init); -- cgit v1.2.3