fix(gravity-forms): enable live label updates for MC4WP field in form editor#818
Merged
dannyvankooten merged 1 commit intoibericode:mainfrom Feb 16, 2026
Conversation
… editor The MC4WP field intentionally overrides get_field_content() to omit the field-level label element, since the checkbox label text IS the field label (avoiding duplication). Add a JavaScript hook via GF's gform_post_set_field_property action in editor_js() to sync label property changes to the checkbox label text in real-time within the form editor. Fixes ibericode#817
e2d2cb2 to
69bec33
Compare
Member
|
Love it. Thanks @faisalahammad! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Summary
Fixes an issue where the "Mailchimp for WordPress" field label in the Gravity Forms editor does not update in real-time when edited. This PR adds a JavaScript hook to the form editor to manually sync label changes to the checkbox text, ensuring a smooth editing experience without modifying the frontend markup structure.
📋 Issue Reference
Fixes #817
🔍 Problem Description
Current Behavior
When editing a form in Gravity Forms, changing the label of the "Mailchimp for WordPress" field does not update the preview in real-time. The change is only reflected after saving the form and refreshing the page.
Expected Behavior
The label should update instantly in the form preview as the user types in the field settings, matching the behavior of native Gravity Forms fields.
Root Cause
The
MC4WP_Gravity_Forms_Fieldclass overridesget_field_content()to deliberately omit the standard field label wrapper. This is done because specific checkbox markup is used where the label text is part of the checkbox element itself (<label for="...">).However, the Gravity Forms editor JavaScript (
SetFieldLabelinform_editor.js) expects the standard label structure (.field_selected label.gfield_label) to perform live updates. Since this structure is missing, the live update fails.✨ Solution Overview
Approach Taken
Instead of modifying the PHP method
get_field_content()(which would introduce a duplicate label element—one as the field label and one as the checkbox label), this solution adds a targeted JavaScript hook to the form editor.We hook into the
gform_post_set_field_propertyaction. When thelabelproperty of amailchimpfield is updated, we manually update the text of the checkbox label in the editor preview.Why This Approach
get_field_content).gform_post_set_field_property).🔧 Changes Made
Files Modified
integrations/gravity-forms/class-gravity-forms.php- Added the JS hook toeditor_js().Detailed Changes
1.
integrations/gravity-forms/class-gravity-forms.phpBefore:
After:
Why This Works:
The
gform.addActionregisters a callback that fires whenever a field property is set in the editor. We check (1) if the property name islabeland (2) if the field type ismailchimp. If both are true, we find the specific label element within that field's checkbox wrapper and update its text content.🧪 Testing Performed
Test Environment
Manual Testing
Test Case 1: Editing the Label
Steps:
Expected Result: The text next to the checkbox in the form preview updates instantly as you type.
Actual Result: ✅ The label updates instantly in the preview.
Screenshot/Evidence:
The label text reflects the input value immediately without a page refresh.
Test Case 2: Frontend Verification
Steps:
Expected Result: There should be only one label for the checkbox, and no duplicate fieldset legend or external label.
Actual Result: ✅ Verified. The markup remains clean:
📊 Performance Impact
Analysis: Negligible impact.
This change adds a few lines of JavaScript that only execute within the Gravity Forms editor admin screen. It has zero impact on frontend performance or database queries.
🔒 Security Considerations
.text(), which safely escapes HTML content, preventing XSS if a user enters malicious scripts into the label field.♿ Accessibility
forattribute) is maintained. The fix purely addresses the admin UI experience.✅ No breaking changes - Fully backward compatible.
Screen recording
Plugin build/zip
mailchimp-for-wp-fix-817.zip
✅ PR Checklist
💬 Questions for Maintainers
None. The implementation uses standard Gravity Forms JS hooks.