How I can prevent form submit in JS/jQuery when one field has a focus on it, while retaining normal behaviour on all other input fields?
Try this:
$('#formID').on('submit', function(){
if ($('input:focus').length){return false;}
});
This is assuming you try to submit the form without click. Because when you click to submit, the input has a blur event and looses focus.
Else: then jcubic's answer might be what you need.
You can use this:
var prevent = false;
$('input').focus(function() {
prevent = true;
}).blur(function() {
prevent = false;
});
$('form').submit(function() {
if (prevent) {
return false;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With