I use typeahead.js as autocomplete textbox.
when I input and select a value from the suggestions, textbox and hiddenfield sets the value correctly. But when I input a value and loose focus of textbox without selecting textbox value and hiddenfield value are missmatch.
How do I clear the value of the textbox and hiddenfield when the input value is not selected from suggestions.
- $(function () {
- $('#txtCustomer').typeahead({
- hint: true,
- highlight: true,
- minLength: 1,
- source: function (request, response) {
- $.ajax({
- url: '/Customer.aspx/GetCustomers',
- data: "{ 'prefix': '" + request + "'}",
- dataType: "json",
- type: "POST",
- contentType: "application/json; charset=utf-8",
- success: function (data) {
- items = []; map = {};
- var obj = JSON.parse(data.d);
- $.each(obj.Data, function (i, value) {
- map[name] = { id: value.CustomerID, name: value.FullName };
- items.push(map[name]);
- });
- response(items);
- },
- error: OnError,
- failure: OnError,
- });
- },
- updater: function (item) {
- $('#hfCustomerId').val(item.id);
- return item;
- }
- });
- });