Reputation: 2801
I am wanting to trigger my placed_changed
function when a submit button is clicked. So here is what I have, I have a searchbox
I assign using google.maps.places.SearchBox
and once I click enter with the search box on focus it triggers the event:
google.maps.event.addListener(searchBox, 'places_changed', function() {
runMainPopulation(searchBox.getPlaces());
});
Which runs the next function. Now what I am trying to do is get this function to run once I click a search button
or I click enter on my searchbox
.
Suggestions, thoughts?
Upvotes: 1
Views: 4866
Reputation: 2801
I figured it out.
I had to initialize the Google searchBox
via google method
post.
For instance:
$(".submit-search").bind('click', function() {
input.focus();
var e = jQuery.Event("keydown");
e.which = 13; // # Some key code value
$(input).trigger(e);
google.maps.event.trigger(searchBox, 'place_changed');
});
This would not work, I am not to sure as to why but it doesn't. submit-search
is the button next to searchBox
also defined as input
.
Now if I initialize my input trigger focus and click through google.maps.event.trigger
it works perfect:
$(".submit-search").bind('click', function() {
google.maps.event.trigger(input, 'focus')
google.maps.event.trigger(input, 'keydown', {
keyCode: 13
});
});
Upvotes: 5