Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update custom-field-type.mdx to add custom validation #587

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/docs/5.35.x/headless-cms/extending/custom-field-type.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ({
Expand All @@ -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>
<Bind validators={validator}>
{bind => (
<Input
{...bind}
Expand Down