I'm writing autocomplete function that should be fired with third element written:
$(document).ready(function() {
$('#button').autocomplete({
minLength: 3,
serviceUrl: '{{contextPath}}/someUrl',
paramName: "suggestion",
onSelect: function (suggestion) {
alert("test");
},
transformResult: function(response) {
return {
suggestions: $.map($.parseJSON(response), function(item) {
return { value: item.x, data: item.y };
})
};
},
});
});
But, this function fires with the first one. Anyone knows why?
Are you using the Ajax AutoComplete? (https://www.devbridge.com/sourcery/components/jquery-autocomplete/)
If so, the right option is called "minChars" not "minLength".
So try using:
$(document).ready(function() {
$('#button').autocomplete({
minChars: 3,
serviceUrl: '{{contextPath}}/someUrl',
paramName: "suggestion",
onSelect: function (suggestion) {
alert("test");
},
transformResult: function(response) {
return {
suggestions: $.map($.parseJSON(response), function(item) {
return { value: item.x, data: item.y};
})
};
},
});
});
If not, can you tell me what library you're using for this autocomplete-function?