From b76c25c9e77806b3fb24987c6d73da25e5a7374b Mon Sep 17 00:00:00 2001 From: Alessio Gravili <70709113+AlessioGr@users.noreply.github.com> Date: Tue, 4 Apr 2023 17:21:54 +0200 Subject: [PATCH] docs: explain lifecycle of validate & beforeValida Caused confusion here: https://discord.com/channels/967097582721572934/1091785894136139808/1092821186959921193 The initial expectation is that beforeValidate runs before any validation happens. However, it seems that client-side validation happens first nonetheless. Please do check if this is 100% correct before merging. --- docs/hooks/collections.mdx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/hooks/collections.mdx b/docs/hooks/collections.mdx index 4a1f05b894f..e7fe7a1bd89 100644 --- a/docs/hooks/collections.mdx +++ b/docs/hooks/collections.mdx @@ -79,7 +79,13 @@ const beforeOperationHook: CollectionBeforeOperationHook = async ({ ### beforeValidate -Runs before the `create` and `update` operations. This hook allows you to add or format data before the incoming data is validated. +Runs before 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: + +1. `validate` runs on the client +2. if successful, `beforeValidate` runs on the server +3. `validate` runs on the server ```ts import { CollectionBeforeOperationHook } from 'payload/types';