-
Notifications
You must be signed in to change notification settings - Fork 92
gpppw-capture-count-as-field-value.js: Fixed an issue with snippet not working with Conditional Logic in play.
#1141
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
Conversation
…not working with Conditional Logic in play. `gpppw-capture-count-as-field-value.js`: Fixed an issue with snippet not working with Conditional Logic in play.
|
Caution Review failedThe pull request is closed. WalkthroughThe code was updated to change the target field ID from "4" to "2" for setting a word count value. The update now checks if the field's value differs before setting it, updates the value if needed, triggers a change event, and returns the word count. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Possibly related PRs
Suggested reviewers
Note 🔌 MCP (Model Context Protocol) integration is now available in Early Access!Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✨ Finishing Touches
🧪 Generate unit tests
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. 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)
gp-pay-per-word/gpppw-capture-count-as-field-value.js (1)
15-18: Excellent fix for the infinite loop issue - consider using strict equality.This conditional check perfectly addresses the "Maximum call stack size exceeded" error by preventing redundant
.change()events. The logic correctly breaks the recursive loop that was occurring when Gravity Forms conditional logic repeatedly re-evaluated.Consider using strict equality (
!==) for more robust comparison:- if ( $field.val() != wordCount ) { + if ( $field.val() !== wordCount ) {This ensures type-safe comparison since form field values are strings while
wordCountmight be a number.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
gp-pay-per-word/gpppw-capture-count-as-field-value.js(1 hunks)
🔇 Additional comments (2)
gp-pay-per-word/gpppw-capture-count-as-field-value.js (2)
12-13: LGTM - Field ID configuration updated correctly.The field ID change from "4" to "2" and the corresponding comment update are correct and align with the specific use case requirements.
20-20: Good practice - explicit return statement improves clarity.Adding the explicit
return wordCount;statement is excellent for filter functions. This ensures the filter chain works correctly and makes the function's intent explicit.
…not working with Conditional Logic in play.
Context
⛑️ Ticket(s): https://secure.helpscout.net/conversation/3028599571/87494
Summary
When using the gpppw_word_count snippet to populate a text field with the word count from a paragraph field, we relied on triggering the
.change()event to ensure that the value could be used in Gravity Forms conditional logic. However, this approach caused a JavaScript error — specificallyUncaught RangeError: Maximum call stack size exceeded— which ultimately prevented the form from loading in the browser.The root cause was that
.change()was being triggered even when the field value hadn’t changed. Since that field was used in conditional logic, Gravity Forms repeatedly re-evaluated conditions and retriggered the same logic, leading to an infinite loop.This PR proposes to add a check to compare the existing value of the field
#input_GFFORMID_2with the newwordCount. The.change()event is now only triggered when the new value differs from the current one, preventing unnecessary logic execution and recursive event loops.By avoiding redundant
.change()triggers, we prevent conditional logic from being re-applied unnecessarily. This breaks the recursive chain and ensures the form loads and functions correctly without JavaScript errors.BEFORE (Samuel):
https://www.loom.com/share/5d47f02f47b24e39a619fe4e6959ffab
AFTER:
https://www.loom.com/share/ffee4fdb11694477a633fa424a0e1ec0