[12.x] Fix conditional validation error messages to preserve case #57686
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.
Problem
When using conditional validation rules like
required_if,prohibited_if,accepted_if, etc., the error messages were incorrectly lowercasing the actual submitted values, making error messages confusing and inconsistent.Example Issues
Issue 1: Case is lost
Issue 2: Boolean confusion
Issue 3: Multi-value scenarios
Root Cause
The
replaceAcceptedIfmethod inReplacesAttributes.phpwas usingreplaceWhileKeepingCasefor the:valueplaceholder, which automatically applied case transformations based on the placeholder format (:value→ lowercase,:VALUE→ uppercase,:Value→ ucfirst).This meant that regardless of what the user submitted, if the translation used
:value(which is standard), the value would always be lowercased.Response to Previous Feedback
Taylor's Test Case
In the previous PR discussion [#57679 ], the following test case was mentioned:
Why this doesn't demonstrate the issue: This example shows validation passing (no errors), so no error message is generated. The issue only manifests when validation fails and error messages need to be displayed.
The Actual Problem Occurs Here
The issue is that when validation fails, the error message was lowercasing the submitted value due to
replaceWhileKeepingCaseapplying transformations based on the:valueplaceholder in the translation string.Why This Fix is Necessary
Testing
Comprehensive tests have been added in
ValidationConditionalRuleErrorMessagesTest.php:Breaking Changes
None. This fix only affects error message formatting, not validation logic. The behavior change makes error messages more accurate and user-friendly.
Related Issues
Fixes [#57678]