I have a requirement to show stock number suggestions in a search box. So I tried using the Jquery autocomplete plugin. I am making an ajax call to a function inside my cfc which returns all the stock numbers in an array.
But the problem is my search box is not showing the suggestions properly. I think this issue is because of numeric values. Any one faced the issue? Here is a replica:
$(function() {
var availableTags = [
1234,
1456,
1789,
1988,
];
$( "#tags" ).autocomplete({
source: availableTags
});
});
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<body>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
</body>
The same is working fine with string data.How to fix it?
As of autocomplete widget expects an array of strings as a source, you can convert your data to array of strings on widget creation:
$(function() {
var availableTags = [
1234,
1456,
1789,
1988,
];
$( "#tags" ).autocomplete({
source: availableTags.map(function(a){
return a.toString()
})
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With