0

Hi everyone i have an issue i want to make an autocomplete in jQuery and i have an json file in the same folder here is the code

var auto = $(function() {
    $("#recherche").autocomplete({
        source: "code.json",
        minLength: 1,
    })
});

and here is a sample of the json file :

{
    "__type": "Featsee",
    "feat": [
        {
            "id": {
                "ID_THING": 1111
            },
            "properties": {
                "CODTHING": "405136",
                "TIONNEMENT": "VRAC"
            }
        }
    ]
}

the html code is the following :

    <label for="tags" >Recherche lot : <input id="recherche" type="text"        class="searchable" placeholder="rechercher ici"/></label>

the plugin is the following :

      <script src="libs/jquery/js/jquery-2.1.1.min.js"></script>
      <script src="libs/jquery/js/jquery-ui.js"></script>

the json file is correct but i want the autocomplete to be jus for CODTHING do you see how can i do that ??

and CODTHING is the code a want it to be the autocomplete

4
  • 2
    Please try to improve your question: What is CODTHING? What autocomplete plugin are you using? Which version? Can you show us some relevant HTML, please Commented Jul 21, 2014 at 12:33
  • is it understandable ?? Commented Jul 21, 2014 at 12:53
  • Nopes. Not understandable! Commented Jul 21, 2014 at 13:34
  • The autocomplete looks like it's apart of jquery ui Commented Jul 21, 2014 at 13:35

1 Answer 1

1

The JSON you provide to jQuery UI's autocomplete needs to be an array of objects with label and value properties or an array of strings.

http://api.jqueryui.com/autocomplete/#option-source

The rest of the answer I can only guess due to the brevity of the JSON you gave us.

If lots.json is just a plain JS file you can look through the `feat" array in your JSON data and return strings based on that.

(function($){

  var lots = $.get('lots.json');

  lots.done(function (results) {

    var data = $.map(results.feat, function (lot) {
      return lot.properties.CODTHING;
    });

    $("#recherche").autocomplete({
      source: data
    });

  });

}(jQuery));

If lots.json is really a server side file that you can feed some data to and filter it there you can use a function like documented on this answer:

JQuery autocomplete source from another js function

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.