Skip to content

Instantly share code, notes, and snippets.

@jkodroff
Created July 18, 2012 22:31
Show Gist options
  • Save jkodroff/3139399 to your computer and use it in GitHub Desktop.
Save jkodroff/3139399 to your computer and use it in GitHub Desktop.
jQuery UI Autocomplete example with complex objects
/// <reference path="../../jquery-1.6.4-vsdoc.js" />
(function ($) {
WEBLINC.areas.add('customerFindAsYouType', function () {
(function () {
WEBLINC.widgets.add('customerFindAsYouType', function (scope) {
$('.customerfindasyoutype', scope)
.keypress(function (e) {
if (e.keyCode == 13) {
e.preventDefault();
}
})
.autocomplete({
source:
function (request, response) {
$.getJSON('/Customer/Search?term=' + request.term, function (data) {
response($.map(data, function (item) {
return {
label: item.Name,
value: item
};
}));
});
},
minLength: 2,
focus:
function (event, ui) {
var customer = ui.item.value;
$(this).val(customer.Name);
event.preventDefault();
},
select:
function (event, ui) {
var customer = ui.item.value;
$(document).trigger('customerSelected', customer);
event.preventDefault();
}
});
});
})();
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment