Easyautocomplete js filter by two fields

1

I need to filter by more than one field, I can currently filter only by "name" but I also need to be able to filter by "code", I have not found in the documentation how to do this, I have tried to add more than one "getValue" but I can not find the right way to do this thanks

I tried to replace getValue with this without results:

getValue: function(element) {
    return $(element).find("name").text() + " " + $(element).find("code").text();
}

getValue: function(element) {
   return element["code"]["name"];
},

link

var options = {
  data: [{
      "name": "Afghanistan",
      "code": "AF"
    },
    {
      "name": "Aland Islands",
      "code": "AX"
    },
    {
      "name": "Albania",
      "code": "AL"
    },
    {
      "name": "Algeria",
      "code": "DZ"
    },
    {
      "name": "American Samoa",
      "code": "AS"
    },
  ],
  getValue: "name",

  list: {
    match: {
      enabled: true
    }
  }
};

$("#provider-json").easyAutocomplete(options);
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/easy-autocomplete/1.3.5/easy-autocomplete.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/easy-autocomplete/1.3.5/easy-autocomplete.themes.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/easy-autocomplete/1.3.5/jquery.easy-autocomplete.min.js"></script>


<input id="provider-json" />
    
asked by Javier Antonio Aguayo Aguilar 11.07.2017 в 16:26
source

1 answer

0

After a few days of searching, I found the solution to filter through two fields. I hope you will greet them.

var options = {
  data: [{
      "name": "Afghanistan",
      "code": "AF"
    },
    {
      "name": "Aland Islands",
      "code": "AX"
    },
    {
      "name": "Albania",
      "code": "AL"
    },
    {
      "name": "Algeria",
      "code": "DZ"
    },
    {
      "name": "American Samoa",
      "code": "AS"
    },
  ],
  getValue: function(element) {
return element.name + " " + element.code;
},

  list: {
    match: {
      enabled: true
    }
  }
};

$("#provider-json").easyAutocomplete(options);
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/easy-autocomplete/1.3.5/easy-autocomplete.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/easy-autocomplete/1.3.5/easy-autocomplete.themes.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/easy-autocomplete/1.3.5/jquery.easy-autocomplete.min.js"></script>


<input id="provider-json" />
    
answered by 11.07.2017 / 18:02
source