feat: block node validations
This commit is contained in:
@@ -4,10 +4,12 @@ import type { AdapterArguments } from '../types'
|
||||
|
||||
import { defaultRichTextValue } from './defaultValue'
|
||||
|
||||
export const richText: Validate<unknown, unknown, RichTextField<AdapterArguments>> = (
|
||||
value,
|
||||
{ required, t },
|
||||
) => {
|
||||
export const richTextValidate: Validate<
|
||||
unknown,
|
||||
unknown,
|
||||
RichTextField<AdapterArguments>,
|
||||
RichTextField<AdapterArguments>
|
||||
> = (value, { required, t }) => {
|
||||
if (required) {
|
||||
const stringifiedDefaultValue = JSON.stringify(defaultRichTextValue)
|
||||
if (value && JSON.stringify(value) !== stringifiedDefaultValue) return true
|
||||
|
||||
@@ -15,7 +15,7 @@ import { Editable, Slate, withReact } from 'slate-react'
|
||||
import type { ElementNode, FieldProps, RichTextElement, RichTextLeaf, TextNode } from '../types'
|
||||
|
||||
import { defaultRichTextValue } from '../data/defaultValue'
|
||||
import { richText } from '../data/validation'
|
||||
import { richTextValidate } from '../data/validation'
|
||||
import elementTypes from './elements'
|
||||
import listTypes from './elements/listTypes'
|
||||
import enablePlugins from './enablePlugins'
|
||||
@@ -80,7 +80,7 @@ const RichText: React.FC<FieldProps> = (props) => {
|
||||
label,
|
||||
path: pathFromProps,
|
||||
required,
|
||||
validate = richText,
|
||||
validate = richTextValidate,
|
||||
} = props
|
||||
|
||||
const elements: RichTextElement[] = admin?.elements || defaultElements
|
||||
|
||||
@@ -104,6 +104,7 @@ export const LinkButton: React.FC<{
|
||||
|
||||
const preferences = await getDocPreferences()
|
||||
const state = await buildStateFromSchema({
|
||||
config,
|
||||
data,
|
||||
fieldSchema,
|
||||
locale,
|
||||
|
||||
@@ -103,6 +103,7 @@ export const LinkElement: React.FC<{
|
||||
|
||||
const preferences = await getDocPreferences()
|
||||
const state = await buildStateFromSchema({
|
||||
config,
|
||||
data,
|
||||
fieldSchema,
|
||||
locale,
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Form, FormSubmit, RenderFields } from 'payload/components/forms'
|
||||
import {
|
||||
buildStateFromSchema,
|
||||
useAuth,
|
||||
useConfig,
|
||||
useDocumentInfo,
|
||||
useLocale,
|
||||
} from 'payload/components/utilities'
|
||||
@@ -35,6 +36,7 @@ export const UploadDrawer: React.FC<
|
||||
const { getDocPreferences } = useDocumentInfo()
|
||||
const [initialState, setInitialState] = useState({})
|
||||
const fieldSchema = fieldProps?.admin?.upload?.collections?.[relatedCollection.slug]?.fields
|
||||
const config = useConfig()
|
||||
|
||||
const handleUpdateEditData = useCallback(
|
||||
(_, data) => {
|
||||
@@ -54,6 +56,7 @@ export const UploadDrawer: React.FC<
|
||||
const awaitInitialState = async () => {
|
||||
const preferences = await getDocPreferences()
|
||||
const state = await buildStateFromSchema({
|
||||
config,
|
||||
data: deepCopyObject(element?.fields || {}),
|
||||
fieldSchema,
|
||||
locale,
|
||||
|
||||
@@ -6,6 +6,7 @@ import type { AdapterArguments } from './types'
|
||||
|
||||
import RichTextCell from './cell'
|
||||
import { richTextRelationshipPromise } from './data/richTextRelationshipPromise'
|
||||
import { richTextValidate } from './data/validation'
|
||||
import RichTextField from './field'
|
||||
|
||||
export function slateEditor(args: AdapterArguments): RichTextAdapter<AdapterArguments> {
|
||||
@@ -45,5 +46,6 @@ export function slateEditor(args: AdapterArguments): RichTextAdapter<AdapterArgu
|
||||
}
|
||||
return null
|
||||
},
|
||||
validate: richTextValidate,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user