fix: text field validation rejecting localized object values#15932
Merged
PatrikKozak merged 1 commit intoMar 12, 2026
Merged
Conversation
…t values
When using `locale: 'all'` with a required localized text field, the
validator receives an object like `{en: "Hello", es: "World"}` instead
of a string. The previous condition `!(typeof value === 'string' ||
Array.isArray(value))` incorrectly rejected these objects.
Aligned the text validator's required check with the textarea validator:
first check `!value` (catches null/undefined/empty string), then check
if string/array has length 0 (catches empty arrays).
Fixes payloadcms#15828
PatrikKozak
approved these changes
Mar 12, 2026
Contributor
|
@omar-y-abdi Fix looks good! Thank you for the contribution - going to merge |
Contributor
|
🚀 This is included in version v3.79.1 |
Contributor
|
@PatrikKozak Any chance something similar could be causing #15651? I just tested 3.79.1 in the hopes that this fix would happen to address that issue as well, but unfortunately that doesn't seem to be the case. Sorry for tagging you, just hoping to get some attention to that issue in case it has slipped between the cracks. 🙏 |
Contributor
|
Hey @marcusforsberg - I'll put this on my radar and get back to you once I've had a chance to take a look |
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 #15828
When using
locale: 'all'with a required localized text field, thetextvalidator incorrectly rejects the value. This happens because:locale: 'all', the value passed to the validator is an object like{en: "Hello", es: "World"}(locale unflattening viamergeLocaleActionshappens after validation inpromise.ts)!(typeof value === 'string' || Array.isArray(value))evaluates totruefor objects, triggering the required errortextareavalidator already handles this correctly by using!value(objects are truthy)Fix
Changed the text validator's required check from:
to:
This aligns with the textarea validator's approach:
!valuecatchesnull,undefined, and empty string""[](truthy but length 0){en: "Hello"}pass because!objisfalseChanges
packages/payload/src/fields/validations.ts— 1-line fix to the required check conditionpackages/payload/src/fields/validations.spec.ts— 3 unit tests (localized object accepted, null rejected, empty string rejected)test/fields/collections/Text/index.ts— AddedlocalizedRequiredTexttest fieldtest/fields/int.spec.ts— Integration test verifyinglocale: 'all'with required localized textTest plan