When is 'focus' called in 'autocomplete'
- by user470184
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");
}
});