Field validators receive no `path` while the form state is built (onChange)
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- react, typescript
Research direction
The missing path is in packages/ui/src/forms/fieldSchemasToFormState/addFieldStatePromise.ts; read the validate(...) call and compare it with fields/hooks/beforeChange/promise.ts and useField. The issue links a branch with a proposed one-line fix and a failing integration test. Confirm the test reproduces the missing path and that validation receives the expected array path after the change.
Written by the indexing model from the issue text.
Description
Describe the Bug
ValidateOptions.path is typed as required, and on submit Payload passes it (path: pathSegments in fields/hooks/beforeChange/promise.ts). On onChange it does not: the validate(...) call in packages/ui/src/forms/fieldSchemasToFormState/addFieldStatePromise.ts leaves path out.
So a validator that uses path, for example to find its own row in an array or block, gets undefined while the editor types. It works only on save.
Link to the code that reproduces this issue
https://github.com/RafalFilipek/payload/tree/fix/ui-validate-path-form-state
This branch has the proposed fix (one line) and an int test that fails without it. It passes path: path.split('.'), the same segments the server and useField use.
Reproduction Steps
{
name: 'items',
type: 'array',
fields: [{
name: 'text',
type: 'text',
validate: (value, { path }) => `Received path: ${JSON.stringify(path)}`,
}],
}
Add a row and type into text.
Expected: ["items","0","text"], the same as on submit.
Actual: undefined.
Which area(s) are affected?
area: ui
Environment Info
Payload 4.0.0-beta, main
Generated by Claude Code
- Dominant language
- TypeScript
- Stars
- 45.5k
- Forks
- 4.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 295
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from payloadcms/payload
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
payloadcms/payload#19060 ·
Maintainers usually reply within 1 day
-
WhereBuilder throws "Cannot read properties of undefined (reading 'value')" when the list URL filters on a field that is not filterablePossibly taken A pull request linked to this issue is open or already merged. OpenBug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
payloadcms/payload#19002 · 1 comment ·
Maintainers usually reply within 1 day
-
Regression: `findByID` with `disableErrors: true` throws `NotFound` for null/empty ids since 3.91.0Possibly taken @Krrishkumar125 claimed this 4 days ago. Openarea: core Bug invalid-reproduction status: needs-triage v3
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
payloadcms/payload#18935 · 1 comment ·
Maintainers usually reply within 1 day
-
bug: Local API call with req resets req.fallbackLocale to defaultLocalePossibly taken A pull request linked to this issue is open or already merged. Openarea: core Bug created-by: Contributor
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
payloadcms/payload#18768 ·
Maintainers usually reply within 1 day
-
[plugin-multi-tenant] Infinite redirect loop with custom tenantFieldName and isGlobal collectionsPossibly taken A pull request linked to this issue is open or already merged. OpenBug plugin: multi-tenant status: needs-triage v3
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
payloadcms/payload#18690 ·
Maintainers usually reply within 1 day
All issues in payloadcms/payload
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
awslabs/visual-asset-management-system#804 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
restatedev/sdk-typescript#813 ·
-
bug desktop P1 session XS
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Merit-Systems/x402scan#1312 ·
-
type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Azure/apiops-cli#331 ·
Maintainers usually reply within 3 days