Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery Autocomplete for 2 input field (same class)
    primarykey
    data
    text
    <p>I have two input fields like this:</p> <pre><code>&lt;input name="accountCode" class="accountCode grid_2"/&gt; &lt;input name="accountCode" class="accountCode grid_2"/&gt; </code></pre> <p>I want to have an autocompleter on both of these fields. I have written the following JavaScript:</p> <pre><code>$(".accountCode").autocomplete( { minLength : 1, source : function(request, response) { $.ajax({ url : baseUrl + "Autocomplete/Account?accountCode=" + $(this).val(), dataType : "json", success : function(data) { response($.map(data, function(item) { return { value : item.accountCode, desc : item.accountName } })); } }); }, focus : function(event, ui) { $(this).val(ui.item.accountCode); return false; }, select : function(event, ui) { // $("#category").val( ui.item.name ); $(this).val(ui.item.value); // $( "#project-description" ).html( ui.item.desc ); return false; } }).data("autocomplete")._renderItem = function(ul, item) { return $("&lt;li&gt;&lt;/li&gt;").data("item.autocomplete", item).append( "&lt;a&gt;&lt;strong&gt;" + item.value + " &lt;/strong&gt;" + item.desc + "&lt;/a&gt;") .appendTo(ul); }; </code></pre> <p>Of course, my server returns JSON data with 2 field: <code>accountCode</code> and <code>accountName</code>.</p> <p>I want both inputs to use the custom renderer in <code>_renderItem</code> so that this will be displayed in the list:</p> <pre><code>"&lt;a&gt;&lt;strong&gt;" + item.value + " &lt;/strong&gt;" + item.desc + "&lt;/a&gt;" </code></pre> <p>For the first field, it works perfectly, but for second field it only displays the <code>accountCode</code> from <code>item.value</code>.</p> <p>I've checked that the JSON received from the server is the same in both cases so the problem is in the Javascript.</p> <p>Do you know why this problem exist?</p>
    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.
 

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