Twitter bootstrap shooting strength selection

I am using the Bootstrap Typeahead plugin in my application and here is my code (this is an example). I am looking for a way to check user selection (basically, if the input does not match the results -> an empty blur field). The result should match. I searched everywhere and could not find anything. Your help would be greatly appreciated.

$('#search').typeahead({ source: function (query, process) { var states = []; var map = {}; var data = [ { "stateCode": "CA", "stateName": "California" }, { "stateCode": "AZ", "stateName": "Arizona" }, { "stateCode": "NY", "stateName": "New York" }, { "stateCode": "NV", "stateName": "Nevada" }, { "stateCode": "OH", "stateName": "Ohio" } ]; $.each(data, function (i, state) { map[state.stateName] = state; states.push(state.stateName); }); process(states); } }); 
+7
source share
2 answers

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(''); } }); 
+11
source

The solution from mccannf works, but in my case with if(parents.indexOf($(this).val()) === -1) { on the blur event.

0
source

All Articles