Skip to content

Commit

Permalink
fix(web): disable boolean field validation (#908)
Browse files Browse the repository at this point in the history
fix: disable boolean field validation
  • Loading branch information
nourbalaha authored Oct 27, 2023
1 parent cbb5938 commit d5527bb
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from "@emotion/styled";
import { CheckboxChangeEvent } from "antd/lib/checkbox";
import { useCallback, useEffect, useState } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";

import Checkbox from "@reearth-cms/components/atoms/Checkbox";
import Form, { FieldError } from "@reearth-cms/components/atoms/Form";
Expand Down Expand Up @@ -260,6 +260,16 @@ const FieldCreationModal: React.FC<Props> = ({
onClose?.(true);
}, [onClose]);

const isRequiredDisabled = useMemo(
() => selectedType === "Group" || selectedType === "Bool",
[selectedType],
);

const isUniqueDisabled = useMemo(
() => selectedType === "Group" || selectedType === "Bool",
[selectedType],
);

return (
<Modal
title={
Expand Down Expand Up @@ -414,13 +424,13 @@ const FieldCreationModal: React.FC<Props> = ({
name="required"
valuePropName="checked"
extra={t("Prevents saving an entry if this field is empty")}>
<Checkbox disabled={selectedType === "Group"}>{t("Make field required")}</Checkbox>
<Checkbox disabled={isRequiredDisabled}>{t("Make field required")}</Checkbox>
</Form.Item>
<Form.Item
name="unique"
valuePropName="checked"
extra={t("Ensures that a multiple entries can't have the same value for this field")}>
<Checkbox disabled={selectedType === "Group"}>{t("Set field as unique")}</Checkbox>
<Checkbox disabled={isUniqueDisabled}>{t("Set field as unique")}</Checkbox>
</Form.Item>
</TabPane>
<TabPane tab={t("Default value")} key="defaultValue" forceRender>
Expand Down

0 comments on commit d5527bb

Please sign in to comment.