diff --git a/demo/collections/RelationshipA.ts b/demo/collections/RelationshipA.ts index 0e6f4f7ea3..ba78729223 100644 --- a/demo/collections/RelationshipA.ts +++ b/demo/collections/RelationshipA.ts @@ -1,5 +1,4 @@ import { CollectionConfig } from '../../src/collections/config/types'; -import { Where } from '../../src/types'; const RelationshipA: CollectionConfig = { slug: 'relationship-a', @@ -24,9 +23,6 @@ const RelationshipA: CollectionConfig = { relationTo: 'localized-posts', hasMany: true, localized: true, - // filterOptions: (args: Args): Where => ({ - // - // }), }, { name: 'postLocalizedMultiple', diff --git a/docs/fields/overview.mdx b/docs/fields/overview.mdx index 379f80a8d2..0a744e43d2 100644 --- a/docs/fields/overview.mdx +++ b/docs/fields/overview.mdx @@ -101,6 +101,26 @@ Example: } ``` +When supplying a field `validate` function, Payload will use yours in place of the default. To make use of the default field validation in your custom logic you can import, call and return the result as needed. + +For example: +```js +import { text } from 'payload/fields/validations'; +const field = + { + name: 'notBad', + type: 'text', + validate: (val, args) => { + if (value === 'bad') { + return 'This cannot be "bad"'; + } + // highlight-start + return text(val, args); + // highlight-end + }, +} +``` + ### Customizable ID Collections ID fields are generated automatically by default. An explicit `id` field can be declared in the `fields` array to override this behavior. diff --git a/fields/validations.js b/fields/validations.js new file mode 100644 index 0000000000..b24ba908b1 --- /dev/null +++ b/fields/validations.js @@ -0,0 +1 @@ +export * from '../dist/fields/validations'; diff --git a/src/fields/validations.ts b/src/fields/validations.ts index 78475520da..a8d31688f2 100644 --- a/src/fields/validations.ts +++ b/src/fields/validations.ts @@ -1,13 +1,19 @@ import defaultRichTextValue from './richText/defaultValue'; import { - ArrayField, BlockField, + ArrayField, + BlockField, CheckboxField, CodeField, DateField, EmailField, - NumberField, PointField, RadioField, RelationshipField, - RichTextField, SelectField, + NumberField, + PointField, + RadioField, + RelationshipField, + RichTextField, + SelectField, TextareaField, - TextField, UploadField, + TextField, + UploadField, Validate, } from './config/types';