twitter/typeahead.js — pull request #546 by ryanpitts (2013-12-09 23:49:17+00:00)
Title: add optional nameKey for input value display

I ran into the same issue referenced in https://github.com/twitter/typeahead.js/issues/193, where the unique value I need from a remote dataset is different than the name I'd like to show users in the input field.

In my case, the typeahead field is matching place names from U.S. Census data, and there's no way to make valueKey truly unique based on those names. We do have a unique geoID, and ultimately that's what we need to retrieve. But it's not a great user experience to see that geoID pop into the input field as they arrow through results.

This change allows an optional `nameKey` when typeahead is initialized, and uses that datum value to populate the input field during `_setInputValueToSuggestionUnderCursor`. If `nameKey` is not provided, it falls back to `valueKey`, just like current behavior.

Just offering this change if you think it's useful to others. If not, no problem ;)