Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery autocomeplete plugin not working with numeric values?

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?

like image 777
Deepak Kumar Padhy Avatar asked Nov 28 '14 08:11

Deepak Kumar Padhy


1 Answers

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()
        })
    });
});
like image 118
Zudwa Avatar answered Sep 17 '22 02:09

Zudwa