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

form-render的Rules 校验中validateTrigger不生效 #1502

Closed
insistence opened this issue Mar 22, 2024 · 4 comments
Closed

form-render的Rules 校验中validateTrigger不生效 #1502

insistence opened this issue Mar 22, 2024 · 4 comments
Assignees
Labels
bug Something isn't working form form-render

Comments

@insistence
Copy link

insistence commented Mar 22, 2024

1.依赖仓库的版本(Dependencies versions)

  • react:^18.0.0
  • form-render:2.4.2
  • table-render:
  • antd:5.15.2

2.问题描述(Bug description)

3.出现问题的 schema demo(Reproduction schema demo)

const schema = {
  type: "object",
  displayType: "row",
  properties: {
    input1: {
      title: "必填",
      type: "string",
      props: {
        rules: [
          {
            required: true,
            message: "必填",
            validateTrigger: "onBlur",
          },
        ],
      },
    },
    input2: {
      title: "数字最大值",
      type: "number",
      max: 2,
      required: true,
    },
    input3: {
      title: "数字最小值",
      type: "number",
      min: 10,
      required: true,
    },
    input4: {
      title: "字符最大长度",
      type: "string",
      max: 2,
      required: true,
    },
    input5: {
      title: "字符最小长度",
      type: "string",
      min: 10,
      required: true,
    },
    input6: {
      title: "url 校验",
      type: "string",
      required: true,
      format: "url",
    },
    input7: {
      title: "email 校验",
      type: "string",
      required: true,
      format: "email",
    },
    input8: {
      title: "图片格式校验",
      type: "string",
      required: true,
      format: "image",
    },
  },
};

export default () => {
  const form = useForm();

  return (
    <FormRender
      schema={schema}
      form={form}
      footer={true}
      validateTrigger={"onBlur"}
    />
  );
};

4.最小复现 demo(Reproduction demo)

form-render demo https://codesandbox.io/p/sandbox/cool-waterfall-d3zm3j

@insistence insistence changed the title form form-render的Rules 校验中validateTrigger不生效 Mar 22, 2024
@lhbxs lhbxs added bug Something isn't working form form-render labels Mar 23, 2024
@lhbxs
Copy link
Collaborator

lhbxs commented Mar 23, 2024

#1503

@lhbxs
Copy link
Collaborator

lhbxs commented Mar 23, 2024

已修复

@lhbxs lhbxs closed this as completed Mar 23, 2024
@insistence
Copy link
Author

insistence commented Mar 24, 2024

感谢大佬的快速回复,但是貌似还是有问题,麻烦看看这个例子test,在schema的rules中设置了validateTrigger,但并没有按照预想效果触发

@insistence
Copy link
Author

import React from "react";
import FormRender, { useForm } from "form-render";

const schema = {
  type: "object",
  displayType: "row",
  properties: {
    input1: {
      title: "必填",
      type: "string",
      rules: [
        {
          required: true,
          message: "rules-onBlur提示",
          validateTrigger: "onBlur",
        },
      ],
    },
    input2: {
      title: "数字最大值",
      type: "number",
      max: 2,
      rules: [
        {
          required: true,
          message: "rules-onFocus提示",
          validateTrigger: "onFocus",
        },
      ],
    },
    input3: {
      title: "数字最小值",
      type: "number",
      min: 10,
      required: true,
    },
    input4: {
      title: "字符最大长度",
      type: "string",
      max: 2,
      required: true,
    },
    input5: {
      title: "字符最小长度",
      type: "string",
      min: 10,
      required: true,
    },
    input6: {
      title: "url 校验",
      type: "string",
      required: true,
      format: "url",
    },
    input7: {
      title: "email 校验",
      type: "string",
      required: true,
      format: "email",
    },
    input8: {
      title: "图片格式校验",
      type: "string",
      required: true,
      format: "image",
    },
  },
};

export default () => {
  const form = useForm();

  return <FormRender schema={schema} form={form} footer={true} />;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working form form-render
Projects
None yet
Development

No branches or pull requests

2 participants