Last active
March 5, 2017 19:31
-
-
Save AmrMekkawy/41887004b685cffa686570bcae53a41d to your computer and use it in GitHub Desktop.
Prevent form submission when choosing a place from google places autocomplete searchbox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// See Demo: https://jsbin.com/wipaze | |
placesSearchbox = $("#google-places-searchbox"); | |
placesSearchbox.on("focus blur", function() { | |
$(this).closest("form").toggleClass('prevent_submit'); | |
}); | |
placesSearchbox.closest("form").on("submit", function(e) { | |
// more about "closest()": https://goo.gl/BzLwZm | |
// more about how to prevent submitting a form: https://goo.gl/LHSvyK | |
if (placesSearchbox.closest("form").hasClass('prevent_submit')) { | |
e.preventDefault(); | |
return false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment