If you are extracting data, states, and a map, you can use them in the .blur function to search:
var data = [ { "stateCode": "CA", "stateName": "California" }, { "stateCode": "AZ", "stateName": "Arizona" }, { "stateCode": "NY", "stateName": "New York" }, { "stateCode": "NV", "stateName": "Nevada" }, { "stateCode": "OH", "stateName": "Ohio" } ]; var states = []; var map = {}; $.each(data, function (i, state) { map[state.stateName] = state; states.push(state.stateName); }); $('#search').typeahead({ source: function (query, process) { process(states); } }).blur(function(){ if(states[$(this).val()] == null) { $('#search').val(''); } });
mccannf
source share