Created
October 23, 2013 16:39
-
-
Save seanwittmeyer/7122077 to your computer and use it in GitHub Desktop.
This is an example of using typeahead.js to prefetch a source, template the results with hogan.js, and send the user to a URL location using the typeahead:autocompleted or typeahead:selected event handlers using jQuery. It takes the result datum and sends a user on their way once the field has been autocompleted (via tab or enter key) or our use…
This file contains 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
$(document).ready(function() { | |
$('.userslist.typeahead').typeahead({ | |
name: 'users', | |
limit: '10', | |
prefetch: '/path/to/users.json', | |
template: [ | |
'<p class="typeahead-num">{{num}}</p>', | |
'<p class="typeahead-name">{{email}}</p>', | |
'<p class="typeahead-city">{{city}}, {{state}}</p>' | |
].join(''), | |
engine: Hogan | |
}); | |
$('.typeahead').on('typeahead:autocompleted', function(evt, item) { | |
window.location.href = 'path/to/users/edit/' + item['userid']; | |
}) | |
$('.typeahead').on('typeahead:selected', function(evt, item) { | |
window.location.href = 'path/to/users/edit/' + item['userid']; | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment