chore: pass mock req through with validate function to slate richText validation function (#5971)

This commit is contained in:
Jarrod Flesch
2024-04-23 10:57:36 -04:00
committed by GitHub
parent 9a5e9313cd
commit 6a745be036

View File

@@ -1,7 +1,7 @@
'use client'
import type { FormFieldBase } from '@payloadcms/ui/fields/shared'
import type { FieldBase } from 'payload/types'
import type { ClientValidate, FieldBase } from 'payload/types'
import type { BaseEditor, BaseOperation } from 'slate'
import type { HistoryEditor } from 'slate-history'
import type { ReactEditor } from 'slate-react'
@@ -88,13 +88,19 @@ const RichTextField: React.FC<
const drawerDepth = useEditDepth()
const drawerIsOpen = drawerDepth > 1
const memoizedValidate = useCallback(
const memoizedValidate: ClientValidate = useCallback(
(value, validationOptions) => {
if (typeof validate === 'function') {
return validate(value, { ...validationOptions, required })
return validate(value, {
...validationOptions,
req: {
t: i18n.t,
},
required,
})
}
},
[validate, required],
[validate, required, i18n],
)
const { path: pathFromContext } = useFieldProps()