Skip to content

Commit

Permalink
Autocomplete: selectFirst option.
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgonzalez committed May 30, 2010
0 parents commit ddbd1e4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions autocomplete/jquery.ui.autocomplete.selectFirst.js
@@ -0,0 +1,15 @@
(function() {

$( ".ui-autocomplete-input" ).live( "autocompleteopen", function() {
var autocomplete = $( this ).data( "autocomplete" ),
menu = autocomplete.menu;

if ( !autocomplete.options.selectFirst ) {
return;
}

menu.activate( $.Event({ type: 'mouseenter' }), menu.element.children().first() );
});

})( jQuery );

27 changes: 27 additions & 0 deletions autocomplete/selectFirst.html
@@ -0,0 +1,27 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete Extensions</title>

<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css">

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.js"></script>
<script src="jquery.ui.autocomplete.selectFirst.js"></script>
<script>
$(function() {
$( "#autocomplete" ).autocomplete({
source: [ "aardvark", "apple", "atom" ],
selectFirst: true
});
});
</script>
</head>
<body>

<input id="autocomplete">

</body>
</html>

0 comments on commit ddbd1e4

Please sign in to comment.