When is 'focus' called in 'autocomplete'
Posted
by
user470184
on Stack Overflow
See other posts from Stack Overflow
or by user470184
Published on 2012-09-12T15:29:37Z
Indexed on
2012/09/12
15:38 UTC
Read the original article
Hit count: 196
JavaScript
|jQuery
The 'focus' documentation from http://jqueryui.com/demos/autocomplete/ states :
focusType:autocompletefocus Before focus is moved to an item (not selecting), ui.item refers to the focused item. The default action of focus is to replace the text field's value with the value of the focused item, though only if the focus event was triggered by a keyboard interaction. Canceling this event prevents the value from being updated, but does not prevent the menu item from being focused.
Code examples
Supply a callback function to handle the focus event as an init option. $( ".selector" ).autocomplete({ focus: function(event, ui) { ... } }); Bind to the focus event by type: autocompletefocus. $( ".selector" ).bind( "autocompletefocus", function(event, ui) { ... });
Using below code sets an attribute called 'mytag' with value 'tester' on all of the autocomplete elements even though I have not selected the elements. Why is the attribute 'focus' not added just when one of the drop downs is focused, instead of being added when page is loaded ?
$("#myDiv").autocomplete({
source: availableTags,
focus: function(event, ui) {
$(".ui-autocomplete li").attr("mytag", "tester");
}
});
© Stack Overflow or respective owner