Skip to content

Commit

Permalink
Autocomplete: add separator option. Fixed #5729 - Separator support for
Browse files Browse the repository at this point in the history
jquery.ui.autocomplete / complete only part of input
  • Loading branch information
blueyed committed Jun 15, 2010
1 parent 9241757 commit 697f92f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions ui/jquery.ui.autocomplete.js
Expand Up @@ -17,7 +17,8 @@
$.widget( "ui.autocomplete", {
options: {
minLength: 1,
delay: 300
delay: 300,
separator: /\s*,\s*/
},
_create: function() {
var self = this,
Expand Down Expand Up @@ -121,14 +122,14 @@ $.widget( "ui.autocomplete", {
if ( false !== self._trigger( "focus", null, { item: item } ) ) {
// use value to match what will end up in the input, if it was a key event
if ( /^key/.test(event.originalEvent.type) ) {
self.element.val( item.value );
self.element.val( self.prefix + item.value );
}
}
},
selected: function( event, ui ) {
var item = ui.item.data( "item.autocomplete" );
if ( false !== self._trigger( "select", event, { item: item } ) ) {
self.element.val( item.value );
self.element.val( self.prefix + item.value );
}
self.close( event );
// only trigger when focus was lost (click on menu)
Expand Down Expand Up @@ -193,6 +194,13 @@ $.widget( "ui.autocomplete", {

search: function( value, event ) {
value = value != null ? value : this.element.val();
if ( this.options.separator ) {
var s = value.split(this.options.separator);
this.prefix = value.substring(0, value.length-s.slice(-1)[0].length);
value = s.pop()
} else {
this.prefix = "";
}
if ( value.length < this.options.minLength ) {
return this.close( event );
}
Expand Down

0 comments on commit 697f92f

Please sign in to comment.