I\'m using jQueryUI autocomplete, and I have a function mapped to the select event, e.g.:
$(\"#someId\").autocomplete({
source: someData,
select: fun
I found very simple way to make it work. Answers above did not work for me.
My input definition:
The autocomplete definition:
$('#search-user-id').autocomplete({
minChars: 3,
paramName: 'searchTerm',
deferRequestBy: 200, // This is to avoid js error on fast typing
serviceUrl: '${pageContext.request.contextPath}/settings/reset/psw/query',
type: 'POST',
onSelect : function(suggestion) {
showUserData(suggestion.dto);
},
onSearchError: function (query, jqXHR, textStatus, errorThrown) {
$('.cev-error-fields.reset-password').find('.error_msg').text(errorThrown).show().fadeOut(7000);
}
});
Trigger it: I am triggering from an ajax defined in other page, I do not put the ajax here for simplicity. Inside the ajax response I just trigger it this way:
$('#search-user-id').val(username);
$('#search-user-id').focus();
It worked.