Skip to content

Instantly share code, notes, and snippets.

@spdustin
Created June 27, 2014 21:36
Show Gist options
  • Save spdustin/3b1176e0a59d26f9595d to your computer and use it in GitHub Desktop.
Save spdustin/3b1176e0a59d26f9595d to your computer and use it in GitHub Desktop.
AutoComplete for SharePoint
var $theField = $('input[title=RelatedAnnouncements]');
var listName = 'Announcements';
var listSvc = _spPageContextInfo.webServerRelativeUrl + '/_vti_bin/listdata.svc/' + listName;
$theField.autocomplete({
source: function(request, response) {
var typed = request.term;
var listSvcFilter = listSvc + '?$filter=startswith(Title,\'' + typed + '\')';
$.getJSON(listSvcFilter, function(data) {
var items = [];
$.each(data.d.results, function(key, val) {
var item = {
label: val.Title,
value: val.Title,
desc: val.Body
};
items.push(item);
});
response(items);
});
},
select: function(event, ui) {
/* logging and updating the description field */
console.log(ui);
$('textarea[title=Description]').val(ui.item.desc);
},
minLength: 2,
delay: 1000
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment