WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] Hooking into the JS autocomplete in [event_form] (3 posts)

  1. Daedalon
    Member
    Posted 1 year ago #

    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?

    http://wordpress.org/extend/plugins/events-manager/

  2. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    not sure... try looking into the jquery docs - http://api.jqueryui.com/autocomplete/

    it may be that you should remove our autocompleter and add your own with tweaks

  3. Daedalon
    Member
    Posted 1 year ago #

    Found it:

    "response( event, ui )Type: autocompleteresponse
    Triggered after a search completes, before the menu is shown. ... This event is always triggered when a search completes, even if the menu will not be shown because there are no results or the Autocomplete is disabled."

    The solution is to add this to a custom .js file. No changes in EM needed.

    $('input[name=location_name]').on("autocompleteresponse", function(){
    	// Action code
    });

    Thanks for the tip and link!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.