docs: update beforeValidate documentation (#10367)

docs: update beforeValidate documentation

These hooks operate similarly across the different contexts they can be
registered in, but were not sufficiently documented as such.

Signed-off-by: Steve Kuznetsov <stekuznetsov@microsoft.com>
This commit is contained in:
Steve Kuznetsov
2025-01-10 01:15:44 -07:00
committed by GitHub
parent a8d6f3f543
commit 21eec876c4
3 changed files with 16 additions and 4 deletions

View File

@@ -91,9 +91,9 @@ The following arguments are provided to the `beforeOperation` hook:
### beforeValidate
Runs before the `create` and `update` operations. This hook allows you to add or format data before the incoming data is validated server-side.
Runs during the `create` and `update` operations. This hook allows you to add or format data before the incoming data is validated server-side.
Please do note that this does not run before the client-side validation. If you added a `validate` function, this would be the lifecycle:
Please do note that this does not run before client-side validation. If you render a custom field component in your front-end and provide it with a `validate` function, the order that validations will run in is:
1. `validate` runs on the client
2. if successful, `beforeValidate` runs on the server

View File

@@ -80,7 +80,13 @@ The following arguments are provided to all Field Hooks:
### beforeValidate
Runs before the `update` operation. This hook allows you to pre-process or format field data before it undergoes validation.
Runs during the `create` and `update` operations. This hook allows you to add or format data before the incoming data is validated server-side.
Please do note that this does not run before client-side validation. If you render a custom field component in your front-end and provide it with a `validate` function, the order that validations will run in is:
1. `validate` runs on the client
2. if successful, `beforeValidate` runs on the server
3. `validate` runs on the server
```ts
import type { Field } from 'payload'

View File

@@ -49,7 +49,13 @@ const GlobalWithHooks: GlobalConfig = {
### beforeValidate
Runs before the `update` operation. This hook allows you to add or format data before the incoming data is validated.
Runs during the `update` operation. This hook allows you to add or format data before the incoming data is validated server-side.
Please do note that this does not run before client-side validation. If you render a custom field component in your front-end and provide it with a `validate` function, the order that validations will run in is:
1. `validate` runs on the client
2. if successful, `beforeValidate` runs on the server
3. `validate` runs on the server
```ts
import type { GlobalBeforeValidateHook } from 'payload'