From dbc9addfae0c9a2aee2d4a1833b2b1d3ba83f8de Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Fri, 16 Apr 2010 11:05:35 +0200 Subject: Autocomplete: Refactored code for array filtering into $.ui.autocomplete.filter, used by remote-with-cache and modified multiple-demo (now with local data); added multiple-remote to also show multiple with remote data --- ui/jquery.ui.autocomplete.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'ui/jquery.ui.autocomplete.js') diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 14a19e4b2..070045d16 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -166,11 +166,7 @@ $.widget( "ui.autocomplete", { if ( $.isArray(this.options.source) ) { array = this.options.source; this.source = function( request, response ) { - // escape regex characters - var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" ); - response( $.grep( array, function(value) { - return matcher.test( value.label || value.value || value ); - }) ); + response( $.ui.autocomplete.filter(array, request.term) ); }; } else if ( typeof this.options.source === "string" ) { url = this.options.source; @@ -308,6 +304,12 @@ $.widget( "ui.autocomplete", { $.extend( $.ui.autocomplete, { escapeRegex: function( value ) { return value.replace( /([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi, "\\$1" ); + }, + filter: function(array, term) { + var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" ); + return $.grep( array, function(value) { + return matcher.test( value.label || value.value || value ); + }); } }); -- cgit v1.2.3