Lille
Lille

Reputation: 305

what javascript will simulate selection from the google maps api 3 places autocomplete dropdown?

I'm trying to automate the selection of items (using jQuery) from the autocomplete dropdown of the google maps api v3 places library. I am unable to determine the javascript required to select the item from the dropdown.

So, for example, here are the steps required to complete a partial field and trigger the dropdown for something like google's demo of this resource:

[EDIT the following code updated to show solution...]

$('input[name=address]').val("525 Bergen Street");
$('input[name=address]').trigger("focus");
$('input[name=address]').simulate("keydown", { keyCode: $.ui.keyCode.DOWN });
$('input[name=address]').simulate("keydown", { keyCode: $.ui.keyCode.ENTER });

[EDIT...see Engineer's reference to simulate, below.]

Any suggestions would be greatly appreciated, thanks,

Lille

Upvotes: 5

Views: 1814

Answers (1)

Engineer
Engineer

Reputation: 48803

Try to use jquery.simulate.js :

$(elem).simulate(mouse_or_keyboard_event_type, options);

Supported event types:

  • mouse: mouseover, mouseout, mousedown, mouseup, mousemove, click, dblclick
  • keyboard: keyup, keydown, keypress

Upvotes: 4

Related Questions