Sha256: 01ff8d5aea7a900e1c6bc31630d4b7f466a478c9ffc7681d42c0f6f6359b8151

Contents?: true

Size: 985 Bytes

Versions: 4

Compression:

Stored size: 985 Bytes

Contents

$.fn.multipleAutocomplete = function(options) {

  var values = options.source;

  var split = function(val) {
    return val.split(/\s*,\s*/);
  };

  var extractLast = function(term) {
    return split(term).pop();
  };

  this.autocomplete({
    minLength: 0,
    source: function(request, response) {
      // delegate back to autocomplete, but extract the last term
      response($.ui.autocomplete.filter(values, extractLast(request.term)));
    },
    focus: function() {
      // prevent value inserted on focus
      return false;
    },
    select: function(event, ui) {
      var terms = split( this.value );
      // remove the current input
      terms.pop();
      // add the selected item
      terms.push( ui.item.value );
      // add placeholder to get the comma-and-space at the end
      terms.push("");
      this.value = terms.join(", ");
      return false;
    },
    open: function(event, ui) {
      $(this).autocomplete('widget').width(500);
    }
  });

};

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
serum-rails-0.2.1 spec/test_apps/rails-2-3/public/javascripts/lib/multiple-autocomplete.js
serum-rails-0.2.0 spec/test_apps/rails-2-3/public/javascripts/lib/multiple-autocomplete.js
serum-rails-0.1.1 spec/test_app/public/javascripts/lib/multiple-autocomplete.js
serum-rails-0.1.0 spec/test_app/public/javascripts/lib/multiple-autocomplete.js