title: jquery multi autocomplete with remote source, showing the results on focus
body: <p>I'd like to wrap standard jQuery UI autocomplete with jQuery plugin for multi-value autocomplete. Everything works good, except one small thing. I'd like to show suggestions on focus. How should I modify my code?</p>
  
  <pre><code>(function ($) {
      $.fn.myautocomplete = function (options) {
          var defaults = {
              source: null,
              minLength: 0,
              separator: ", "
          };
  
          var o = {};
          $.extend(o, defaults, options);
  
          var split = function(val) { return val.split(/,\s*/); };
          var extractLast = function(term) { return split(term).pop(); };
  
          if (o.source == null) return this;
  
          return this.each(function () {
              $(this).autocomplete({
                  source: function(request, response) {
                      $.ajax({
                          url: o.source,
                          data: { term: extractLast(request.term) },
                          success: function(data) {
                              response($.map(data, function(item) {
                                  return { label: item.Name };
                              }));
                          }
                      });
                  },
                  search: function() {
                      return extractLast(this.value).length &gt; o.minLength;
                  },
                  focus: function() {
  
                          //$(this).trigger('keydown.autocomplete');
                          $(this).data("autocomplete").search($(this).val());
                      //return false;
                  },
                  select: function(event, ui) {
                      var terms = split(this.value);
                      terms.pop();
                      terms.push(ui.item.label);
                      terms.push("");
                      this.value = terms.join(o.separator);
                      return false;
                  }
              });
          });
      };
  })(jQuery);
  </code></pre>
  
  <p>I've tried everything that you see inside focus handler.</p>