Skip to content

Update JS validation to always remove errors when valid regardless of…#3125

Open
Crabcyborg wants to merge 1 commit into
masterfrom
update_js_validation_to_always_remove_errors_when_valid
Open

Update JS validation to always remove errors when valid regardless of…#3125
Crabcyborg wants to merge 1 commit into
masterfrom
update_js_validation_to_always_remove_errors_when_valid

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Jun 5, 2026

… validation setting

That this update changes
With this update, JS validation does not need to be enabled in order for field errors to disappear on change events.

Where this update might break
I'd mostly look out for JS errors in the console. Validating all fields always might introduce an error somewhere in our validation logic. I don't think it's likely though as I'm not aware of any issues with our JS validation setting throwing errors. If there are, these are good to catch anyway.

It also wouldn't hurt to test with JS validation on as well.

To replicate

  1. Ensure the form does not have JS validation enabled.
  2. Submit the form in a case where errors would appear (like required field validation).
  3. Update the field.

Previously, the error would remain. Now, it disappears.

Before

Screen.Recording.2026-06-05.at.11.39.51.AM.mov

After

Screen.Recording.2026-06-05.at.11.39.20.AM.mov

Summary by CodeRabbit

Bug Fixes

  • Improved URL field error handling to ensure stale validation errors are properly cleared even when JavaScript validation is disabled, while preventing new validation errors from appearing unless validation is active.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 5, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

The form validation flow is updated to support conditional error UI. maybeValidateChange now calls validateField unconditionally for URL fields with a flag indicating whether JS validation is enabled, and validateField accepts an addErrors parameter to control whether validation errors get re-added to the UI or only cleared.

Changes

Conditional Form Field Validation

Layer / File(s) Summary
Conditional error UI in validation flow
js/formidable.js
maybeValidateChange now unconditionally calls validateField with a boolean flag indicating JS validation mode, and validateField branches error-UI logic: when the flag is true, existing errors are cleared and repopulated; when false, errors are only removed if the field has no current validation errors.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A form that clears its errors right,
Whether validation runs in JS light,
Or stands alone with flags so clear—
Stale mistakes just disappear! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is incomplete (ends with 'regardless of…') but clearly references the main change: removing validation errors regardless of a setting, which aligns with the actual changes to error handling in validateField.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch update_js_validation_to_always_remove_errors_when_valid

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@deepsource-io
Copy link
Copy Markdown

deepsource-io Bot commented Jun 5, 2026

DeepSource Code Review

We reviewed changes in b7cd07c...b32a1b2 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Jun 5, 2026 2:34p.m. Review ↗
JavaScript Jun 5, 2026 2:34p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

Comment thread js/formidable.js
Comment on lines +341 to +343
for ( key in errors ) {
addFieldError( fieldContainer, key, errors );
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap the body of a for-in loop in an if statement with a hasOwnProperty guard


Looping over objects with a for in loop will include properties that are inherited through the prototype chain. This behavior can lead to unexpected keys in your for loop.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
js/formidable.js (1)

636-636: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Pass through addErrors when validating the confirmation field

  • confirmField() calls validateField( confirmField ) without the addErrors argument at line 636, so validateField() falls back to addErrors = true.
  • This breaks the intended behavior when validateField() is called with addErrors = false (e.g., via maybeValidateChange() using hasClass(form, 'frm_js_validate')): the main field won’t add new errors, but the confirmation field can.
  • Fix: pass the same addErrors value into validateField( confirmField, addErrors ) (thread it through, or compute it from confirmField.closest('form')).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@js/formidable.js` at line 636, The confirmation-field validation is calling
validateField(confirmField) without forwarding the addErrors flag, so
confirmField() should call validateField(confirmField, addErrors) (or compute
addErrors from confirmField.closest('form') the same way maybeValidateChange()
does) to preserve the caller's addErrors=false behavior; update confirmField()
to accept/derive the addErrors boolean and pass it through to validateField so
the confirmation field won't add errors when the main validation is invoked with
addErrors=false.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@js/formidable.js`:
- Line 636: The confirmation-field validation is calling
validateField(confirmField) without forwarding the addErrors flag, so
confirmField() should call validateField(confirmField, addErrors) (or compute
addErrors from confirmField.closest('form') the same way maybeValidateChange()
does) to preserve the caller's addErrors=false behavior; update confirmField()
to accept/derive the addErrors boolean and pass it through to validateField so
the confirmation field won't add errors when the main validation is invoked with
addErrors=false.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3eced1b6-1ee5-47a7-b778-fefbc9a991c7

📥 Commits

Reviewing files that changed from the base of the PR and between b7cd07c and b32a1b2.

📒 Files selected for processing (1)
  • js/formidable.js

@Crabcyborg Crabcyborg requested a review from garretlaxton June 5, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant