I want to autofill the input field when user insert right value and escape the input field. An example of this is https://www.redbus.in/ I am using url string to send data request, and after that receive the result. I want to keep sending the data request and receiving results even the user excape the field? Then first value of the list with results must be selected. THAN YOU FOR THE HELP !
My code is:
jQuery(document).ready(function(){
jQuery( "#econt_offices_town" ).autocomplete({
minLength: 2,
autoFocus: true,
source: function( request, response ) {
jQuery.ajax({
url: ajaxurl,
dataType: "json",
data: {
action:'handle_ajax',
city: request.term
},
success: function( data ) {
response(jQuery.map(data, function(item) {
retu {
label: item.label,
value: item.value,
city_id: item.id,
post_code: item.post_code
};
}));
}, //end of success
}); //end of ajax
}, //end of source
select: function( event, ui ) {
var city_id = ui.item.city_id;
var post_code = ui.item.post_code;
jQuery('#econt_offices_postcode').val(post_code);
jQuery('#office_locator').show(); //show office locator button after the city is selected
jQuery('#econt_offices_postcode, label[for="econt_offices_postcode"], #econt_offices, label[for="econt_offices"]').show();
jQuery.ajax({
url: ajaxurl,
dataType: "json",
data: {
action:'handle_ajax',
office_city_id: city_id,
delivery_type: 'to_office'
},
success: function( data ) {
jQuery('#econt_offices').empty()
jQuery.each(data, function(key, value) {
jQuery('#econt_offices').append(jQuery("<option/>", {
value: value.id,
text: value.value + ' [о.к.:' + value.id + ']'
}));
});
calculate_loading(); //calculate loading cost for shipping to office
} //end of success
}); //end of ajax
}, //end of select
}); //end of #econt_offices_town .autocomplete
