Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery autocomplete - Select first item
    primarykey
    data
    text
    <p>I am using jquery autocomplete which I am populating from a ruby on rails application and I am creating a custom autcomplete like so:</p> <pre><code> $.widget( "custom.code_complete", $.ui.autocomplete, { _renderMenu: function( ul, items ) { var self = this, currentCategory = ""; $ul = ul; $.each( items, function( index, item ) { if ( item.category != currentCategory ) { ul.append( "&lt;li class='ui-autocomplete-category'&gt;" + item.category + "&lt;/li&gt;" ); currentCategory = item.category; } self._renderItem( ul, item ); }); } }); $("#r-code").code_complete({ source: "URL", minLength: 2, select: function(event, ui) { $(".button-row").fadeIn(); get_details(ui.item.url); } }); </code></pre> <p>I am redirecting a user from another page to the page with the autocomplete form with a parameter in the URL which is a code used for the search, here is the JS to do the search:</p> <pre><code>function ac_search(code) { $("#r-code").val(code); $("#r-code").code_complete('search', code); } </code></pre> <p>This performs the search perfectly and displays the drop down list of results. I am trying to have the script then select the first result in the list. I have tried doing it via a selector:</p> <pre><code>$(".ui-menu-item:first a").click(); </code></pre> <p>This finds the correct element in the autocomplete list but when I try and simulate a click it gives this error:</p> <pre><code>TypeError: ui.item is null </code></pre> <p>Is it possible to programmatically click the first item in the autocomplete results list?</p> <p>Cheers</p> <p>Eef</p>
    singulars
    1. This table or related slice is empty.
    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. 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