How to prevent Twitter typeahead from filling in the input with the selected value?

前端 未结 5 1599
深忆病人
深忆病人 2020-12-18 08:17

I\'m using Twitter\'s typeahead plugin for autocompletion with a text input. I want to change the behavior so that instead of putting the selected option\'s value into the t

5条回答
  •  余生分开走
    2020-12-18 08:59

    Struggled with this for a while, before I found how to clear the text when you select an option:

    $("#typeahead-input").on('typeahead:selected', function (event, datum, name) {
       $(this).typeahead("val", "");
       // Do something with the datum...
    });
    

提交回复
热议问题