Files
payload/test/hooks/collections/Value/index.ts
Jarrod Flesch b3e7a9d194 fix: incorrect value inside beforeValidate field hooks (#11433)
### What?
`value` within the beforeValidate field hook was not correctly falling
back to the document value when no value was passed inside the request
for the field.

### Why?
The fallback logic was running after the beforeValidate field hooks are
called.

### How?
Run the fallback logic before running the beforeValidate field hooks.

Fixes https://github.com/payloadcms/payload/issues/10923
2025-02-27 16:00:27 -05:00

35 lines
748 B
TypeScript

import type { CollectionConfig } from 'payload'
export const valueHooksSlug = 'value-hooks'
export const ValueCollection: CollectionConfig = {
slug: valueHooksSlug,
fields: [
{
name: 'slug',
type: 'text',
hooks: {
beforeValidate: [
({ value, siblingData }) => {
siblingData.beforeValidate_value = String(value)
return value
},
],
beforeChange: [
({ value, siblingData }) => {
siblingData.beforeChange_value = String(value)
return value
},
],
},
},
{
name: 'beforeValidate_value',
type: 'text',
},
{
name: 'beforeChange_value',
type: 'text',
},
],
}