### 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
35 lines
748 B
TypeScript
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',
|
|
},
|
|
],
|
|
}
|