Skip to content

Instantly share code, notes, and snippets.

@sastraxi
Last active August 29, 2015 14:23
Show Gist options
  • Save sastraxi/5e2ec50349f2bfbb65b7 to your computer and use it in GitHub Desktop.
Save sastraxi/5e2ec50349f2bfbb65b7 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
$(function() {
// prepare a typeahead using the song IDs
$('#songId').autocomplete({
serviceUrl: "@{Publishers.clientSongIds}",
paramName: "prefix",
dataType: "json",
transformResult: function(response, originalQuery) {
return {
"suggestions": $.map(response.results, function(result) {
return {
value: result.track,
data: result.songId
}
})
};
},
formatResult: function (suggestion, currentValue) {
return "<span style='float:right'>" + suggestion.data + "</span><span>" + suggestion.value + "</span>";
},
showNoSuggestionNotice: true,
onSelect: function (suggestion) {
$(this).val(suggestion.data);
$("#mainForm").submit();
}
});
});
</script>
<input type="text" id="songId" class="form-control input-lg" name="songId"
placeholder="Song ID" autocomplete="off" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment