Google maps autocomplete bounces back already cleared text ... odd .... odd ... odd

I have this weird behavior from Google MAP autocomplete (or maybe I missed) ... ideas? Odd:

  • You enter sth as input, for example. "London"
  • You press [ENTER]
  • Press the [CLEAR] button
  • You press enter
  • You go beyond "input"

....... and voila! Already cleared in the text of step-3 ("London" in our example) will return to the entrance ... Why?

And here is the code:

<!DOCTYPE html>
<html>
<head>
     <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=places"></script>
</head>
<body>

    <h1>MY FORM</h1>
    <input type='text' id='myInput' size='50' placeholder='Enter text'>
    <input type='button' value='clear' onclick='clearInput()'>

    <script>
                var myInput = document.getElementById('myInput');
                var autocomplete = new google.maps.places.Autocomplete(myInput);
                function clearInput(){
                    myInput.value = '';
                }

                myInput.addEventListener('change', function(){
                        console.log(event['target']['value']);

                }, false);

    </script>
    </body>
</html>
+2
source share
1 answer

The answer to the “why” is complex, because the source of the API source is compressed, it is difficult to say what is actually happening.

, -, (, ).

4 :

focus, keydown, keyup, blur

, .

: :

function clearInput(){
  google.maps.event.trigger(myInput,'focus');
  myInput.value = '';
  google.maps.event.trigger(myInput,'keydown',{keyCode:46});
  google.maps.event.trigger(myInput,'keyup',{keyCode:46});
  google.maps.event.trigger(myInput,'blur');
}

, .

+3

All Articles