Skip to content

Payload bug / inconsistency in how text handles localized + required #15828

@sharmasourabh

Description

@sharmasourabh

Describe the Bug

Payload bug / inconsistency in how text handles "localized + required" during validation, especially when you’re writing localized objects (or using locale: 'all'). The moment you change the field type from text to textarea or change the required: false, create API calls start working (also stored as a string).

payload.config.ts:

export const locales = ['hi', 'en']
export default buildConfig({
  ...
  localization: {
      locales: locales.map((locale) => ({
        code: locale,
        label: {
          hi: 'हिन्दी',
          en: 'English',
        }[locale]!,
      })),
      defaultLocale: 'hi',
      fallback: true,
  },
  ...
})

Pages.ts

  ...
  fields: [
      {
        name: 'title',
        type: 'text',
        localized: true,
        required: true,
      },
  ...

Link to the code that reproduces this issue

https://github.com/sharmasourabh/localized-required-text-issue-

Reproduction Steps

To replicate the issue, run the following command:

$ pnpm payload run src/seed.ts 
ValidationError: The following field is invalid: Title
....
status: 400,
  [cause]: {
    id: undefined,
    collection: 'pages',
    errors: [
      {
        label: 'Title',
        message: 'This field is required.',
        path: 'title'
      }
    ],

I have also tried using locale: 'all'. However same issue:

await payload.create({
      overrideAccess: true,
      collection: COLLECTION_SLUG,
      fallbackLocale: false,
      locale: 'all',
      data: {...}
    })

Which area(s) are affected?

Not sure

Environment Info

payload: 3.78.0
Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 24.6.0
  Available memory (MB): 16384
  Available CPU cores: 8

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions