Skip to content

fix: skip default validation for virtual fields#16015

Merged
DanRibbens merged 2 commits into
payloadcms:mainfrom
jhb-dev:fix/virtual-fields-skip-validation
Apr 1, 2026
Merged

fix: skip default validation for virtual fields#16015
DanRibbens merged 2 commits into
payloadcms:mainfrom
jhb-dev:fix/virtual-fields-skip-validation

Conversation

@jhb-dev

@jhb-dev jhb-dev commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

What?

Virtual fields (virtual: true or virtual: "path") no longer get a default type-based validator during field sanitization. They receive a noop validator instead.

Why?

Virtual fields are populated server-side (via hooks, built-in population, or plugins), so their value is undefined in form state. The default validator causes false validation errors in the admin UI that users cannot resolve.

How?

In sanitize.ts, when assigning a default validator, check if the field is virtual first. If so, assign () => true instead of the type-based validator. Explicit validate functions are still preserved.

Fixes #16012
Related #16013


@DanRibbens DanRibbens self-assigned this Apr 1, 2026
@DanRibbens DanRibbens merged commit e09c619 into payloadcms:main Apr 1, 2026
159 checks passed
@github-actions

github-actions Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

🚀 This is included in version v3.82.0

milamer pushed a commit to milamer/payload that referenced this pull request Apr 20, 2026
### What?

Virtual fields (`virtual: true` or `virtual: "path"`) no longer get a
default type-based validator during field sanitization. They receive a
noop validator instead.

### Why?

Virtual fields are populated server-side (via hooks, built-in
population, or plugins), so their value is `undefined` in form state.
The default validator causes false validation errors in the admin UI
that users cannot resolve.

### How?

In `sanitize.ts`, when assigning a default validator, check if the field
is virtual first. If so, assign `() => true` instead of the type-based
validator. Explicit `validate` functions are still preserved.

Fixes payloadcms#16012
Related payloadcms#16013

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1213743778134481
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Virtual fields run client-side validation despite being non-editable

3 participants