Files
payload/test/fields/collections/Text/CustomError.tsx
2024-03-19 00:59:56 -04:00

25 lines
602 B
TypeScript

'use client'
import React from 'react'
import { useFormFields, useFormSubmitted } from '@payloadcms/ui'
import { useField } from '@payloadcms/ui'
const CustomError: React.FC<any> = (props) => {
const { path: pathFromProps } = props
const submitted = useFormSubmitted()
const { path } = useField(pathFromProps)
const field = useFormFields(([fields]) => (fields && fields?.[path]) || null)
const { valid } = field || {}
const showError = submitted && !valid
if (showError) {
return <div className="custom-error">#custom-error</div>
}
return null
}
export default CustomError