Last update breaks submit on enter
-
Cause: Contact Form X global Enter handler
In the bundled JavaScript there is this handler:
$(document.body).on('keypress', function(e) { if (e.which == 13) { if (!$('#cfx-message').is(':focus')) contactFormXSubmit(e); }});
What it does:
Listens for Enter (keyCode/which 13) on document.body
If the focus is not on #cfx-message, it calls contactFormXSubmit(e)
contactFormXSubmit() calls e.preventDefault() at the start
So Enter is intercepted for the whole page whenever you are not focused on the CFX message field.
Effect:
In the search overlay (#overlay-search-input): pressing Enter triggers this handler instead of submitting the search form.
In other forms (login, registration, etc.): same behavior.
The only time Enter behaves normally is when focus is on #cfx-message.
Fix (in the Contact Form X plugin)
The logic should only run when the user is in the contact form, not everywhere else. For example:
// Only handle Enter when user is inside the contact form$(document.body).on('keypress', function(e) { if (e.which == 13) { var $target = $(e.target); // Only intercept if we're in a cfx form field (but not the message textarea) if ($target.closest('.cfx-form, #cfx').length && !$target.is('#cfx-message')) { contactFormXSubmit(e); } }});
Or, more conservatively, only run when the event originates inside the contact form:
if (e.which == 13) { var $target = $(e.target); if ($target.closest('#cfx, .cfx-form').length && !$target.is('#cfx-message')) { contactFormXSubmit(e); }}
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.