Force Javascript keydown into Google Maps autocomplete input!

Asked

Viewed 80 times

0

Folks I have the following precise problem that by clicking "Enter" on an input with Google Maps auto complete, then it press the down key to select a Google Maps option.. tried several ways but it didn’t work out! I have the following code:

jQuery('.find-by__autocomplete').on('keydown', function(e) {
    if(e.keyCode == 13) {
        e.which = 40;
        jQuery(".find-by__autocomplete").trigger(e);
    }
});

Thank you!

  • It stays inside the iframe ? If it is the browser does not allow you to simulate a click or any keyboard Trigger on a page outside your domain

  • No, it is a normal input on the page is only using google maps autocomplete

  • Put this part of the code together in the question, html

1 answer

0

Resolved as follows!

jQuery("#autocomplete").keypress(function (e) {
    e.cancelBubble = true;

    if (e.keyCode === 13 || e.keyCode === 9) {
        google.maps.event.trigger(e.target, "keydown", {
            keyCode: 40,
            hasRanOnce: true
        });

        google.maps.event.trigger(e.target, "keydown", {
            keyCode: 13,
            hasRanOnce: true
        });
    }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.