jqgrid autocomplete with JSONArray in edit form

jqgrid autocomplete with JSONArray in edit form

Hi, I'm new to jquery and am using the edit form from the jqgrid plugin.

I generate the autocomplete from an ajax function which returns a JSONArray but the autocomplete doesn't adjust to what i am typing, but it always shows all suggestions no matter what I type into the text field. Here is my code:
  1. colModel: [....
  2.             {
  3.                 name: 'ScenarioName',
  4.                 index: 'ScenarioName',
  5.                 sortable: true,
  6.                 sorttype: 'text',
  7.                 editable: true,
  8.                 edittype: 'custom',
  9.                 editoptions: {
  10.                     custom_element : autocomplete_element,
  11.                     custom_value   : autocomplete_value
  12.                 },
  13.                 hidelg: true
  14.             }
  15. ....]

  1. function autocomplete_element(value, options) {
  2.   // creating input element
  3.   var $ac = $('<input type="text"/>');
  4.   $ac.val(value);
  5.   var $source = "ajax/listAutoComplete?fieldName="+options.id;
  6.   $ac.autocomplete({
  7.     source: $source,
  8.     autosearch: true,
  9.     minLength: 2,
  10.     selectFirst: true
  11.   });
  12.   return $ac;
  13. }

  14. function autocomplete_value(elem, op, value) {
  15.   if (op == "set") {
  16.     $(elem).val(value);
  17.   }
  18.   return $(elem).val();
  19. }

If I change the source to a static array (e.g. ["1","11","111"]) then it works fine.

Any suggestions?