buildFormState with select evaluates admin.condition against data with unselected fields already deleted

Open
#19,604 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@hassanabrar202 is already working on this.

Since Nov 15, 2026.

  • #19605 by @hassanabrar202 — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
40/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
react, typescript
Domain
frontend

Research direction

Start at forms/fieldSchemasToFormState/calculateDefaultValues/promise.ts where stripUnselectedFields deletes unselected keys, then read fieldSchemasToFormState/index.tsx to see how fullData is assigned and how iterateFields supplies sibling data to admin.condition. Reproduce by running the linked tests/int/selectCondition.int.spec.ts against the reported repro, covering both the top-level extra case and the nested address.city case. Done means conditions see the pre-strip copy while the returned state is still limited to select. Note a linked pull request (#19605) is already open, so coordinate before starting.

Written by the indexing model from the issue text.

Description

area: ui Bug Payload OSS
Describe the Bug

In 4.0.0-beta.9, a form state request with select checks each field's admin.condition against data that is already missing every unselected field. Any field whose condition reads a field outside select comes back with passesCondition: false, so it disappears from the form. A form that edits one field of a document (<Form select={{ extra: true }}>) therefore loses that field as soon as its condition depends on another field.

Cause: with select, stripUnselectedFields deletes unselected keys from the data object, first in calculateDefaultValues (forms/fieldSchemasToFormState/calculateDefaultValues/promise.ts) and again in iterateFields. That same object is what admin.condition later receives. At the top level it is both data and fullData (fieldSchemasToFormState/index.tsx: let fullData = dataWithDefaultValues), and for a group it is the group's sibling data.

A fix that makes the repro pass: take a copy of data before stripping when select is set (structuredClone(data)), use it as fullData, and in iterateFields pass the matching sibling object from that copy (looked up by parentPath) as the condition's siblingData. The returned state stays limited to select.

Link to the code that reproduces this issue

https://github.com/cgilly2fast/payload-select-condition-repro

Reproduction Steps
  1. pnpm install && cp .env.example .env
  2. pnpm test:int tests/int/selectCondition.int.spec.ts

src/collections/Posts.ts has extra, shown only when title is set, and address.city, shown only when its sibling address.country is US. The test builds form state for a post with title: 'Hello' and address.country: 'US':

  • No select (control): both fields pass their conditions.
  • select: { extra: true }: extra gets passesCondition: false. Expected: it passes, because title is set.
  • select: { address: { city: true } }: address.city gets passesCondition: false. Expected: it passes, because country is US.
Which area(s) are affected?

area: ui

Environment Info

payload 4.0.0-beta.9, @payloadcms/ui 4.0.0-beta.9, @payloadcms/db-sqlite 4.0.0-beta.9, Node 24, created with create-payload-app@beta -t blank.

Dominant language
TypeScript
Stars
45.8k
Forks
4.4k
Avg merge
2d 16h
Merged PRs (30d)
251

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from payloadcms/payload

All issues in payloadcms/payload

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.