Я использую bootstrap typeahead, и мне интересно, как мне заставить его отправить при нажатии кнопки ввода? Другими словами, если я набрал «привет» в ввод типа ввода и нажал кнопку ввода, как бы отправить «привет»?Typeahead submit with enter
Я уже сделал это так, чтобы typeahead не автоматически выбирал первый результат.
Это мой код:
<form method="POST" action="script.php">
<input name="typeahead_field" class="typeahead" data-provide="typeahead" autocomplete="off" type="text">
</form>
JQuery:
$('.typeahead').typeahead({
items: 10,
source: function (query, process) {
$.ajax({
url: 'typeahead.php',
type: 'POST',
dataType: 'JSON',
data: 'query=' + query,
success: function(data) {
process(data);
}
});
},
highlighter: function(data) {
// code that returns each result
return html;
},
updater: function(data) {
// code that redirects the user if they click the selection
},
});
Пожалуйста, помогите!