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

1

5

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

Slipcase answered 8/4, 2012 at 12:17 Comment(2)
You want to go the result of a specific query without typing or clicking something?Wellworn
Yes, I'm automating these steps in a web app integration test framework that allows me to execute javascript code, such as that shown above. What I'm missing is adequate knowledge of the events that I would need to trigger on the google maps api v3 places autocomplete dropdown (BTW -- at this point I'm indifferent between simulating the goal 1) with downkey and enter or 2) mouse actions).Slipcase
G
4

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
Gehrke answered 8/4, 2012 at 18:15 Comment(2)
This might be useful once I know what events trigger the desired result, namely, selection of an item from the google maps api v3 places autocomplete dropdown, but otherwise, it seems to me it will just duplicate my guesswork so far in jQuery.Slipcase
Engineer's recommendation to use jquery.simulate.js eventually got me what I needed. I would recommend this tool and using the 'key' event simulations for anybody scratching their head over an autocomplete task.Slipcase

© 2022 - 2024 — McMap. All rights reserved.