diff --git a/.changeset/quiet-bats-mate.md b/.changeset/quiet-bats-mate.md new file mode 100644 index 0000000000..674f7f29ee --- /dev/null +++ b/.changeset/quiet-bats-mate.md @@ -0,0 +1,8 @@ +--- +"@comet/admin": patch +--- + +Update required validator in `Field` to correctly handle falsey values + +Previously, the validator incorrectly returned errors for all falsey values, e.g. the number `0`. +Now, it only returns an error for `undefined`, `null`, `false` and empty strings. diff --git a/packages/admin/admin/src/form/Field.tsx b/packages/admin/admin/src/form/Field.tsx index b3cbf3678b..ef48daaa13 100644 --- a/packages/admin/admin/src/form/Field.tsx +++ b/packages/admin/admin/src/form/Field.tsx @@ -6,7 +6,12 @@ import { FormattedMessage } from "react-intl"; import { FieldContainer, FieldContainerProps } from "./FieldContainer"; import { useFinalFormContext } from "./FinalFormContextProvider"; -const requiredValidator = (value: any) => (value ? undefined : ); +const requiredValidator = (value: any) => { + if (value === undefined || value === null || value === false || value === "") { + return ; + } + return undefined; +}; const composeValidators = (...validators: Array<(value: any, allValues: object) => any>) =>