I have an Elementor form with multiple fields. I want the form to be automatically submitted as soon as there is no focus on any of the fields like clicking somewhere.
My solution for a form with a single field looks like this:
$( '#form-field' ).blur( function() {
$( '#form' ).submit();
});
How can I extend this to all fields of the form #form
?
Thanks for any help!
EDIT:
Thanks for the answers.
As far as favilian's answer goes, the if statement would be interesting. So if the user leaves one form field, there has to be a check to see if we are not in any other field of the form. Only if not in any other field, submit the form. The form looks (simplified) like this:
<form method="post" id="form">
<input type="text" name="form_fields[field1]" id="form-field-field1">
<input type="text" name="form_fields[field2]" id="form-field-field2">
<input type="text" name="form_fields[field3]" id="form-field-field3">
<button type="submit">Save</button>
</form>
So, for example, case one:
The user clicks in the first field (#form-field-field1
) and leaves the form, the form should be submitted, because there is no focus on field two (#form-field-field2
) and three (#form-field-field3
).
Case two:
The User clicks again in the first field and continues to the second field (via click or tab). This should not trigger the submit since another field of the form is foccused/active. After that, the user leaves the form by clicking. No other form field is active. Now the form should be submitted.
How can the if statement look like that checks if not another field is focussed?