Skip to content

Commit

Permalink
docs: update beforeValidate documentation (#10367)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
stevekuznetsov authored Jan 10, 2025
1 parent a8d6f3f commit 21eec87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/hooks/collections.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion docs/hooks/fields.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 7 additions & 1 deletion docs/hooks/globals.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 21eec87

Please sign in to comment.