Skip to content

Instantly share code, notes, and snippets.

Created May 3, 2011 10:54
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Backbone View for jQuery UI Autocomplete inputs
var Autocomplete = Backbone.View.extend({
render: function() {
var choices = this.options.choices,
selected = this.options.selected,
iterator = this.options.iterator,
label = this.options.label,
allowDupes = this.options.allowDupes,
$el = $(this.el);
source: function(request, response) {
var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), 'i');
response(choices.filter(function(model) {
return iterator(model, matcher);
focus: function(event, ui) {
return false;
select: function(event, ui) {
if (!allowDupes) {
return false;
}).data('autocomplete')._renderItem = function(ul, item) {
return $('<li/>')
.data('item.autocomplete', item)
return this;
Copy link

xunker commented Dec 12, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment