From 0c852995cc59d1af043fa03f9438f6337676e728 Mon Sep 17 00:00:00 2001 From: Joshua Dutton Date: Wed, 3 May 2023 12:23:41 -0600 Subject: [PATCH] Update custom-field-type.mdx to add custom validation Custom validation is now added as part of the example --- .../headless-cms/extending/custom-field-type.mdx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/docs/5.35.x/headless-cms/extending/custom-field-type.mdx b/src/docs/5.35.x/headless-cms/extending/custom-field-type.mdx index 94bf43b7e..97f8455f5 100644 --- a/src/docs/5.35.x/headless-cms/extending/custom-field-type.mdx +++ b/src/docs/5.35.x/headless-cms/extending/custom-field-type.mdx @@ -127,6 +127,7 @@ As our next step, we'll define a renderer for our new field. The renderer determ ```ts secretTextFieldRendererPlugin.tsx import React from "react"; import { CmsEditorFieldRendererPlugin } from "@webiny/app-headless-cms/types"; +import { ValidationError } from "@webiny/validation"; import { Input } from "@webiny/ui/Input"; export default (): CmsEditorFieldRendererPlugin => ({ @@ -142,8 +143,15 @@ export default (): CmsEditorFieldRendererPlugin => ({ render({ field, getBind }) { const Bind = getBind(); + const validator = (value: any) => { + if (value.length < 8) { + return new ValidationError("Value must be at least 8 characters long to have enough entropy to be secret enough."); + } + return true; + } + return ( - + {bind => (