Normally an Autosuggest control works when we press a key, it will suggest all values.Suppose database has lakhs of records then the problem arise, when user presses key each time it will go to Database and searches this will make Autosuggestion slower so here we will see a Autosuggest which searches when user permit it only by pressing Enter Key
Introduction
Normally all Autosuggest searches when user types any thing on Autosuggest,here we will look a control
which suggests on enter key press
Objective
Autosuggest control which suggest only on enter key
Using the code
it is really simple to make a control like this, want to make search only when user press enter key
below code will make you clear
if(key==13) return true other wise return false this is the area which makes enter key suggestion
// $(document).ready(function () {
$("#ItemName").autocomplete({
search: function (event, ui) {
var key = event.keyCode;
if (key == 13) {
return true;
}
else
return false;
},
source: function (request, response) {
$.ajax({
url: '@Url.Action("ItemAutoSuggestByName")',
data: { autoSuggestText: request.term },
dataType: 'json',
type: 'POST',
success: function (data) {
response(data); // You may have to perform post-processing here depending on your data.
}
});
},
select: function (event, ui) {
$('#ItemName').val(ui.item ? ui.item.value : 'Select');
}
});
Conclusion
You can download source and check