Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>jQueryUI requires a value and/or label field if you are using an object:</p> <blockquote> <p><strong>Multiple types supported:</strong> </p> <p><strong>Array</strong>: An array can be used for local data. There are two supported formats: An array of strings: [ "Choice1", "Choice2" ] </p> <p><strong>An array of objects with label and value properties:</strong> [ { label: "Choice1", value: "value1" }, ... ] The label property is displayed in the suggestion menu. The value will be inserted into the input element when a user selects an item. If just one property is specified, it will be used for both, e.g., if you provide only value properties, the value will also be used as the label.</p> </blockquote> <p>Source: <a href="http://api.jqueryui.com/autocomplete/#option-source">http://api.jqueryui.com/autocomplete/#option-source</a></p> <p>With that in mind you have to adopt your data, to include the value property, which you just assign to the name (e.g. <code>$.each(employees, function(){ this.value = this.name });</code> ...)</p> <p>Now the other thing you have to define, is how you want to filter. This can be done by defining the <strong>source</strong>.</p> <p>Example:</p> <pre><code> $("#txtEmployeeName").autocomplete({ source: function (request, response) { var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i"); var matching = $.grep(employees, function (value) { var name = value.value; var id = value.id; return matcher.test(name) || matcher.test(id); }); response(matching); } }); </code></pre> <p>Fiddler example: <a href="http://fiddle.jshell.net/YJkTr/">http://fiddle.jshell.net/YJkTr/</a></p> <p>Full code: </p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Demo&lt;/title&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt; &lt;link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(function () { var employees = [ { "value": "Tom", "id": "1" }, { "value": "Stefan", "id": "2" }, { "value": "Martin", "id": "3" }, { "value": "Sara", "id": "4" }, { "value": "Valarie", "id": "5" }, ] $("#txtEmployeeName").autocomplete({ source: function (request, response) { var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i"); var matching = $.grep(employees, function (value) { var name = value.value; var id = value.id; return matcher.test(name) || matcher.test(id); }); response(matching); } }); }); &lt;/script&gt; &lt;/head&gt; &lt;body style="font-size: 62.5%;"&gt; &lt;div class="ui-widget"&gt; &lt;form&gt; &lt;label for="txtEmployeeName"&gt;Developer:&lt;/label&gt; &lt;input id="txtEmployeeName" /&gt; &lt;/form&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload