diff --git a/web/src/components/atoms/Form/index.tsx b/web/src/components/atoms/Form/index.tsx index 73a4594167..a30b6c0968 100644 --- a/web/src/components/atoms/Form/index.tsx +++ b/web/src/components/atoms/Form/index.tsx @@ -1,5 +1,5 @@ import { Form, FormInstance } from "antd"; -import { Rule } from "antd/lib/form"; +import { Rule, RuleObject } from "antd/lib/form"; import { FormItemProps } from "antd/lib/form/FormItem"; import { FormItemLabelProps } from "antd/lib/form/FormItemLabel"; import { FieldError, ValidateErrorEntity } from "rc-field-form/lib/interface"; @@ -12,5 +12,6 @@ export type { FieldError, FormInstance, Rule, + RuleObject, ValidateErrorEntity, }; diff --git a/web/src/components/molecules/Content/Form/fields/utils.ts b/web/src/components/molecules/Content/Form/fields/utils.ts index 5dfccd9303..c12744c9f6 100644 --- a/web/src/components/molecules/Content/Form/fields/utils.ts +++ b/web/src/components/molecules/Content/Form/fields/utils.ts @@ -1,10 +1,13 @@ -import { Rule } from "@reearth-cms/components/atoms/Form"; +import { RuleObject } from "@reearth-cms/components/atoms/Form"; export const checkIfEmpty = (value: unknown) => value === undefined || value === null || value === ""; -export const requiredValidator = (_: Rule, value: unknown) => { - if (checkIfEmpty(value) || (Array.isArray(value) && value.every(v => checkIfEmpty(v)))) { +export const requiredValidator = (rule: RuleObject, value: unknown) => { + if ( + rule.required && + (checkIfEmpty(value) || (Array.isArray(value) && value.every(v => checkIfEmpty(v)))) + ) { return Promise.reject(); } return Promise.resolve();