0
It seems like you want the following behavior:
- When the user types a partial employee ID (e.g., "1234"), show autocomplete suggestions for matching employee IDs.
- If the user selects an autocomplete suggestion or manually enters a complete employee ID (e.g., "1234590"), display the corresponding employee's name without further autocomplete suggestions.
$("#txtLineManagerId").autocomplete({
source: function (request, response) {
var searchText = request.term;
$.ajax({
url: '@Url.Action("GetAllEmployeeBasedSearchText", "Resignation")',
data: { searchText: searchText },
method: "GET",
dataType: "json",
success: function (data) {
response($.map(data, function (item) {
return { label: item.EmployeeID, value: item.EmployeeID, employeeName: item.EmployeeName };
}));
}
});
},
select: function (event, ui) {
// When an item is selected, update LineManagerName input with the selected Employee Name
$("#LineManagerName").val(ui.item.employeeName);
// Clear autocomplete suggestions after selection
$(this).autocomplete("close");
},
minLength: 4,
});
$("#txtLineManagerId").change(function () {
var employeeid = $(this).val();
$.ajax({
url: '@Url.Action("GetEmployeeName", "Resignation")',
data: { employeeid: employeeid },
method: "GET",
dataType: "json",
success: function (data) {
$("#LineManagerName").val(data);
}
});
});
