Clear autocomplete field value after select address

KodeFor.Me

I am trying to build an app based on Google Maps and I have create an autocomplete field that allowing the end user to enter his address manualy.

Also, my app, requires the start address of a trip to located within predefined by the admin boundaries.

What I like to do, is when the end user try to enter the start trip address, and the address it is outside the boundaries, to clear the autocomplete field.

Unfortunatelly I cannot clear the field. While the console show me the value of the field empty, the browser still contains the last entered address.

The code I am using is the following:

//  Build a new AutoComplete object
autocomplete            =   new google.maps.places.Autocomplete(
    $addressField[0],    //  Set the address field
    {
        types   :   [
            'geocode'
        ],
        bounds  :   map.getBounds()
    }
);

//  Add an event listener for autocomplete object
google.maps.event.addListener(
    autocomplete,
    'place_changed',                //  And track the change event
    function()
    {
        var place           =   autocomplete.getPlace();
        var latLng          =   new google.maps.LatLng(place.geometry.location.lat(),   place.geometry.location.lng());
        var isWithinPolygon =   areaPolygon.containsLatLng(latLng);

        if(!isWithinPolygon)
        {
            // NOTE : I have also try the .val() method but with no effect.
            $addressField.attr('value', '').attr('data-lat',  '').attr('data-lng', '');
            console.warn('This address it is not located within the area boundaries');
        }
        else
        {
            $addressField.attr('data-lat',  place.geometry.location.lat()).attr('data-lng', place.geometry.location.lng());
        }
    }
);

Finally, here is my screen shot on my App and on my Console:

Application Screenshot

enter image description here

Element inspection

enter image description here

Console Messages

enter image description here

Can somebody to help me with this issue ?

Dr.Molle

Additionally clear the place-property of the autocomplete:

 autocomplete.set('place',void(0));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Select Attribute value and field value Using jquery autocomplete

From Dev

Clear item from Chrome address bar autocomplete

From Dev

Is there a way to clear value in a particular field after failed submission?

From Dev

Unable to clear autocomplete value once selected in knockout

From Dev

Jquery autocomplete clear textbox value if match not found

From Dev

Clear select field options based on another field

From Dev

Input field shows model value instead of label after select

From Dev

django InlineAdmin: Fill Field Value after a Select-Change (ForeignKey)

From Dev

how to select content of field after setting its value?

From Dev

How do I clear the previous text field value after submitting the form with out refreshing the entire page?

From Dev

Cannot get validation message to clear after updating input field value via JavaScript

From Dev

Cannot get validation message to clear after updating input field value via JavaScript

From Dev

:hover stops after hovering autocomplete field

From Dev

How to clear the field after typeahead selection?

From Dev

django clear form field after a submit

From Dev

How to clear input field after submitting to database

From Dev

Clear input field after button click

From Dev

SELECT grouping by value in field

From Dev

JQuery UI AutoComplete inserts <br> after select

From Dev

JavaScript emptying the input after autocomplete select

From Dev

Business rule fails to clear field value

From Dev

Clear text field value on click the checkbox nsis

From Dev

SELECT field value minus previous field value

From Dev

Select jQuery autocomplete value by its id

From Dev

JQuery autocompleted does not clear the input after select

From Dev

Select text field after creating it

From Dev

Validate an input field after select

From Dev

How to clear a text field on entering value in other text field

From Dev

Clear selected value(s) for Kendo multi select

Related Related

  1. 1

    Select Attribute value and field value Using jquery autocomplete

  2. 2

    Clear item from Chrome address bar autocomplete

  3. 3

    Is there a way to clear value in a particular field after failed submission?

  4. 4

    Unable to clear autocomplete value once selected in knockout

  5. 5

    Jquery autocomplete clear textbox value if match not found

  6. 6

    Clear select field options based on another field

  7. 7

    Input field shows model value instead of label after select

  8. 8

    django InlineAdmin: Fill Field Value after a Select-Change (ForeignKey)

  9. 9

    how to select content of field after setting its value?

  10. 10

    How do I clear the previous text field value after submitting the form with out refreshing the entire page?

  11. 11

    Cannot get validation message to clear after updating input field value via JavaScript

  12. 12

    Cannot get validation message to clear after updating input field value via JavaScript

  13. 13

    :hover stops after hovering autocomplete field

  14. 14

    How to clear the field after typeahead selection?

  15. 15

    django clear form field after a submit

  16. 16

    How to clear input field after submitting to database

  17. 17

    Clear input field after button click

  18. 18

    SELECT grouping by value in field

  19. 19

    JQuery UI AutoComplete inserts <br> after select

  20. 20

    JavaScript emptying the input after autocomplete select

  21. 21

    Business rule fails to clear field value

  22. 22

    Clear text field value on click the checkbox nsis

  23. 23

    SELECT field value minus previous field value

  24. 24

    Select jQuery autocomplete value by its id

  25. 25

    JQuery autocompleted does not clear the input after select

  26. 26

    Select text field after creating it

  27. 27

    Validate an input field after select

  28. 28

    How to clear a text field on entering value in other text field

  29. 29

    Clear selected value(s) for Kendo multi select

HotTag

Archive