-
Notifications
You must be signed in to change notification settings - Fork 91
gw-disable-submission-on-enter.js
: Fixed an issue with disable enter snippet not working with Conversational Forms.
#1100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…r snippet not working with Conversational Forms.
WalkthroughThe event handling logic for disabling form submission via the Enter key in Gravity Forms was refactored. The implementation switched from a jQuery-based delegated 'keypress' handler on Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Document
participant .gform_wrapper
participant Form
User->>Document: keydown (Enter)
Document->>Document: Check if target is inside .gform_wrapper
alt Target inside .gform_wrapper and not textarea/button
Document->>Document: stopImmediatePropagation(), preventDefault()
Note right of Document: Form submission blocked
else Not relevant target
Document->>Document: No action
end
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
gravity-forms/gw-disable-submission-on-enter.js (1)
10-17
: Improved event handling addresses Conversational Forms compatibility.The changes correctly resolve the compatibility issue with the Conversational Forms Add-on by:
- Using
addEventListener
with capture phase (true
) to ensure the handler runs before other handlers- Adding
stopImmediatePropagation()
to prevent other event handlers from executing- Checking if the target is within a Gravity Form using
closest()
A few minor improvement suggestions:
document.addEventListener( 'keydown', function(e) { var isGravityForm = e.target.closest( '.gform_wrapper' ) !== null; - var code = e.keyCode || e.which; - if ( code == 13 && ! jQuery( e.target ).is( 'textarea,input[type="submit"],input[type="button"]' ) && isGravityForm ) { + // Check for Enter key (code 13) + if ( (e.key === 'Enter' || e.keyCode === 13) && isGravityForm && + ! jQuery( e.target ).is( 'textarea,input[type="submit"],input[type="button"]' ) ) { e.stopImmediatePropagation(); e.preventDefault(); } }, true );These changes:
- Use the modern
e.key
property (with fallback)- Add a comment for clarity about the key code
- Reorder the condition checks for better short-circuiting
Context
⛑️ Ticket(s): https://secure.helpscout.net/conversation/2931919718/83124
Summary
Disable Submission on Enter snippet and Gravity Forms Conversational Forms Add-on incompatibility. The snippet works as expected when Conversational forms is not active on the form, but once it is active on the form, the snippet doesn't work.
We have updated to
addEventListener
withkeydown
to catchEnter
across all input elements..gform_wrapper
as a parent to confirm the event is inside a Gravity Form field.stopImmediatePropagation()
to prevent interference from other listeners.This works reliably with GF Conversational Forms Add-on, and continues to work with normal form preview/form front end pages.
BEFORE (Credits: Roxy):
https://www.loom.com/share/9c577fd7af1d47f090458e99e9118444
AFTER:
https://www.loom.com/share/050bd75bd63b475c9827a516083b4f84