WordPress.org

Support

Support » Plugins and Hacks » Events Manager » [Resolved] Hooking into the JS autocomplete in [event_form]

[Resolved] Hooking into the JS autocomplete in [event_form]

  • 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/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Marcus

    @netweblogic

    NetWebLogic Support

    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

    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!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Hooking into the JS autocomplete in [event_form]’ is closed to new replies.
Skip to toolbar