Search code examples
javascriptjquerytwitter-typeahead

Cannot set text field value after selecting suggestion from typeahead


I cannot set the value for a text field after selecting (twitter) typeahead suggestion

This does not work:

  $("#location").on("typeahead:selected", function(eventObject, suggestion, name) {
  console.log(suggestion.stop_id);
  $("#location").val(suggestion.stop_id);
});

While this works: (but I want text entered in same text field)

  $("#location").on("typeahead:selected", function(eventObject, suggestion, name) {
  console.log(suggestion.stop_id);
  $("#destination").val(suggestion.stop_id);
});

Solution

  • Had to replace return null with return suggestion.value in display parameter function of typeahead to put desired value in field.