Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AmrMekkawy/41887004b685cffa686570bcae53a41d to your computer and use it in GitHub Desktop.
Save AmrMekkawy/41887004b685cffa686570bcae53a41d to your computer and use it in GitHub Desktop.
Prevent form submission when choosing a place from google places autocomplete searchbox
// 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