Now it is looking like this
I am workingin jquery autoplete below is my code where i want to search city.
jQuery('#citySearch').autoplete({
serviceUrl: basePath + '/selectMycities.json',
paramName: "tagName", //
onSelect: function(suggestion) {
cityID = suggestion.data;
cityId=cityID;
jQuery("#cityId").val(cityID);
return false;
},
transformResult: function(response) {
return {
suggestions: jQuery.map(jQuery.parseJSON(response), function(item) {
return {
value: item.cityName,
data: item.cityId,
id: item.cityId
};
})
};
}
});
Now in above autoplete i want to set autoFocus as true but it is not working. please help.
It should like 2nd image
Now it is looking like this
I am workingin jquery autoplete below is my code where i want to search city.
jQuery('#citySearch').autoplete({
serviceUrl: basePath + '/selectMycities.json',
paramName: "tagName", //
onSelect: function(suggestion) {
cityID = suggestion.data;
cityId=cityID;
jQuery("#cityId").val(cityID);
return false;
},
transformResult: function(response) {
return {
suggestions: jQuery.map(jQuery.parseJSON(response), function(item) {
return {
value: item.cityName,
data: item.cityId,
id: item.cityId
};
})
};
}
});
Now in above autoplete i want to set autoFocus as true but it is not working. please help.
It should like 2nd image
I have found the solution with reference to these https://www.devbridge./sourcery/ponents/jquery-autoplete/
I used autoSelectFirst property and i got the respected result as like 2nd image.
autoSelectFirst: if set to true, first item will be selected when showing suggestions. Default value false.
jQuery('#citySearch').autoplete({
autoSelectFirst: true,
serviceUrl: basePath + '/selectMycities.json',
paramName: "tagName", //
onSelect: function(suggestion) {
cityID = suggestion.data;
cityId=cityID;
jQuery("#cityId").val(cityID);
return false;
},
transformResult: function(response) {
return {
suggestions: jQuery.map(jQuery.parseJSON(response), function(item) {
return {
value: item.cityName,
data: item.cityId,
id: item.cityId
};
})
};
}
});
autofocus will highlight first item, while selectFirst will select first item.
jQuery('#citySearch').autoplete({
selectFirst: true,
autoFocus: true,
serviceUrl: basePath + '/selectMycities.json',
paramName: "tagName", //
onSelect: function(suggestion) {
cityID = suggestion.data;
cityId=cityID;
jQuery("#cityId").val(cityID);
return false;
},
transformResult: function(response) {
return {
suggestions: jQuery.map(jQuery.parseJSON(response), function(item) {
return {
value: item.cityName,
data: item.cityId,
id: item.cityId
};
})
};
}
});
u have to add
$( "#citySearch" ).focus();
https://fiddle.jshell/1vfcgcco/1/
or something like this...
$("#auto").autoplete({
source: function(request, response) {
var results = $.ui.autoplete.filter(src, request.term);
response(results.slice(0, 4));
}
});
http://jsfiddle/vqwBP/1098/