{"record":{"id":"47bb5e83dd4c90e9","repo":"payloadcms/payload","slug":"the-following-fields-are-invalid-fieldpaths","errorCode":null,"errorMessage":"The following fields are invalid: ${fieldPaths}","messagePattern":"The following fields are invalid: (.+?)","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"packages/payload/src/fields/hooks/beforeChange/index.ts","lineNumber":77,"sourceCode":"    fieldLabelPath: '',\n    fields: (collection?.fields || global?.fields)!,\n    global,\n    mergeLocaleActions,\n    operation,\n    overrideAccess: overrideAccess!,\n    parentIndexPath: '',\n    parentIsLocalized: false,\n    parentPath: '',\n    parentSchemaPath: '',\n    req,\n    siblingData: data,\n    siblingDoc: doc,\n    siblingDocWithLocales: docWithLocales,\n    skipValidation,\n  })\n\n  if (errors.length > 0) {\n    throw new ValidationError(\n      {\n        id,\n        collection: collection?.slug,\n        errors,\n        global: global?.slug,\n        req,\n      },\n      req.t,\n    )\n  }\n\n  for (const action of mergeLocaleActions) {\n    await action()\n  }\n\n  return data\n}\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/fields/hooks/beforeChange/index.ts#L59-L95","documentation":"Thrown by the beforeChange hook when one or more fields failed validation during a create or update. Payload runs every field's `validate` function via `traverseFields`, collects all `ValidationFieldError` entries, and throws a single `ValidationError` whose `data.errors` lists each offending field path and message. The message shown is the aggregated summary.","triggerScenarios":"POST/PATCH a document missing a required field; submitting data of the wrong type (e.g. string into a number field); failing a custom `validate` function; JSON field failing schema validation; select field with a value not in `options`.","commonSituations":"Admin form submission with empty required inputs; API client sending incomplete payloads; conditional fields whose `admin.condition` hid them but the data still required values; localized fields missing in the active locale.","solutions":["Read `err.data.errors` for the exact field paths and per-field messages.","Correct each flagged field's value in the submitted payload.","If validation is wrong, adjust the field's `validate` or `required` config rather than disabling validation.","For programmatic creates, run the same checks client-side before calling the Local/API."],"exampleFix":"// before: missing required field\nawait payload.create({ collection: 'posts', data: { title: '' } })\n// after\nawait payload.create({ collection: 'posts', data: { title: 'Hello', content: '...' } })\n// read errors\ntry { ... } catch (e) {\n  if (e?.data?.errors) console.error(e.data.errors) // [{ field: 'title', message: 'required' }]\n}","handlingStrategy":"try-catch","validationCode":"// client-side pre-flight: run the same required/type checks before calling the API\nfunction preflight(collection, data) {\n  const errors = []\n  for (const f of collection.fields) {\n    if (f.required && (data[f.name] === undefined || data[f.name] === null || data[f.name] === '')) {\n      errors.push({ field: f.name, message: 'This field is required.' })\n    }\n  }\n  return errors\n}\nconst errs = preflight(collection, payloadData)\nif (errs.length) throw new Error('preflight failed: ' + JSON.stringify(errs))","typeGuard":"function isValidationError(err: any): err is { name: 'ValidationError'; data: { errors: { field: string; message: string }[] } } {\n  return err?.name === 'ValidationError' && Array.isArray(err?.data?.errors)\n}","tryCatchPattern":"try {\n  await payload.create({ collection: 'posts', data })\n} catch (err) {\n  if (err?.name === 'ValidationError' && Array.isArray(err.data?.errors)) {\n    // map err.data.errors -> [{ field, message }] for form rendering\n    for (const e of err.data.errors) formErrors[e.field] = e.message\n  } else {\n    throw err\n  }\n}","preventionTips":["Mirror required/type rules on the client and pre-validate before submit.","In custom `validate` functions, return clear messages and stable field paths.","Use `admin.condition` carefully — hidden required fields still validate unless you also relax `required`."],"tags":["validation","beforechange","create","update","runtime","api"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}