When adding a new event, I'd like to be able to hook into the autocomplete event. The intent is to trigger other actions in the form whenever the autocomplete is run.
It was simple enough to do with a modification to includes/js/events-manager.js by adding one line at the lines 559-562, changing them from:
}).data( "autocomplete" )._renderItem = function( ul, item ) {
html_val = "<a>" + item.label + '<br><span style="font-size:11px"><em>'+ item.address + ', ' + item.town+"</em></span></a>";
return jQuery( "<li></li>" ).data( "item.autocomplete", item ).append(html_val).appendTo( ul );
};
to
}).data( "autocomplete" )._renderItem = function( ul, item ) {
html_val = "<a>" + item.label + '<br><span style="font-size:11px"><em>'+ item.address + ', ' + item.town+"</em></span></a>";
jQuery(document).triggerHandler('em_autocomplete_done_hook');
return jQuery( "<li></li>" ).data( "item.autocomplete", item ).append(html_val).appendTo( ul );
};
This still has the downside that it doesn't trigger when the autocomplete is called but yields no results. I'm looking forward to trigger an action whenever autocomplete is called, regardless of it finding results. Could such a hook be added or is there another way I could trigger an action every time jQuery( "#em-location-data input#location-name" ).autocomplete() is called?