fix(checkout): restrict client-side validation to current step fields only#763
Conversation
… only When a multi-step checkout form has account fields (email, username, password) on a later step, the client-side validator was firing required rules for ALL fields across ALL steps on every step submission. This caused spurious validation errors on step 1 (e.g. a plan-only step) because email/username/password were required but not yet visible. Fix: - PHP: expose wu_checkout.step_fields (step_id => [field_ids]) via get_checkout_variables() so JS knows which fields belong to each step. - JS: validate_client_side() now reads the current checkout_step from the hidden form input and filters allRules to only the fields on that step before running validation. Falls back to all rules for legacy single-step forms where step_fields is unavailable. This mirrors the existing server-side behaviour in get_validation_rules() which already filters to $this->step['fields'] for non-final steps. Fixes #762
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe changes implement step-aware client-side validation in the checkout process. The PHP backend now exports a Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Completion Summary
|
🔨 Build Complete - Ready for Testing!📦 Download Build Artifact (Recommended)Download the zip build, upload to WordPress and test:
🌐 Test in WordPress Playground (Very Experimental)Click the link below to instantly test this PR in your browser - no installation needed! Login credentials: |
|
Performance Test Results Performance test results for 00f05c8 are in 🛎️! Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown. URL:
|
|
All CI checks pass. Awaiting human review approval to merge (branch protection requires at least one approving review). Summary of changes:
Resolves #762 aidevops.sh v3.6.167 plugin for OpenCode v1.3.16 with claude-sonnet-4-6 spent 15m and 13,111 tokens on this as a headless worker. |
Completion Summary
Merged via PR #763 to main.
|
Summary
Fixes spurious validation errors (Email is required, Username is required, Password is required) that appeared on the first checkout step when that step only contained a
pricing_tableandsubmit_button. The errors only affected logged-out users.Root Cause
The client-side validation added in #397 called
validate_client_side()with ALL validation rules for ALL fields across ALL steps. When a multi-step form has account fields (email, username, password) on a later step, those required rules fired immediately on step 1 — before the user ever saw those fields.The server-side
get_validation_rules()already handles this correctly by filtering rules to$this->step['fields']for non-final steps. The client-side validator had no equivalent step-scoping.Fix
PHP (
inc/checkout/class-checkout.php): Addedstep_fields(step_id → [field_ids]) to theget_checkout_variables()output so the JS knows which fields belong to each step.JS (
assets/js/checkout.js):validate_client_side()now reads the currentcheckout_stepfrom the hidden form input and filtersallRulesto only the fields on that step before running validation. Falls back to all rules for legacy single-step forms wherestep_fieldsis unavailable.Testing
get_validation_rules()step-filtering behaviourRuntime Testing
self-assessed— UI/form validation change. No payment, auth, or data-deletion paths affected.Resolves #762
aidevops.sh v3.6.167 plugin for OpenCode v1.3.16 with claude-sonnet-4-6 spent 7m and 9,529 tokens on this as a headless worker.
Summary by CodeRabbit