Created
September 23, 2014 16:17
-
-
Save dbarrionuevo/699b78363d5263aa5f0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
show_autocomplete: function (itemName, collection) { | |
$('.' + itemName).autocomplete({ | |
source: function (request, response) { | |
var contains1, containsMatcher1, startsWith1, startsWithMatcher1, term; | |
term = $.ui.autocomplete.escapeRegex(request.term); | |
startsWithMatcher1 = new RegExp('^' + term, 'i'); | |
startsWith1 = $.grep(collection, function (value) { | |
return startsWithMatcher1.test(value.label || value.value || value); | |
}); | |
containsMatcher1 = new RegExp('\\b' + term, 'i'); | |
contains1 = $.grep(collection, function (value) { | |
return $.inArray(value, startsWith1) < 0 && containsMatcher1.test(value.label || value.value || value); | |
}); | |
return response(startsWith1.concat(contains1)); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment