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

[Bug Report] x-validator 并不能按照预期禁用 #4214

Open
1 task
electroluxcode opened this issue Sep 5, 2024 · 0 comments · May be fixed by #4216
Open
1 task

[Bug Report] x-validator 并不能按照预期禁用 #4214

electroluxcode opened this issue Sep 5, 2024 · 0 comments · May be fixed by #4216

Comments

@electroluxcode
Copy link

electroluxcode commented Sep 5, 2024

  • I have searched the issues of this repository and believe that this is not a duplicate.

原因在于 源码中 getRulesKeys 的函数 只对key值的存在进行了校验,如果key存在那么就认为这条校验存在

Steps to reproduce

import React from 'react'
import { createForm } from '@formily/core'
import { FormProvider,createSchemaField } from '@formily/react'
import { registerValidateRules } from '@formily/validator'
import { Input, FormItem, FormButtonGroup, Submit } from '@formily/antd';

// step1: 注册自定义全局校验规则
registerValidateRules({
  required(e,_,ctx) {
    if (!e) return `${ctx.field.title}:自定义校验字段不能为空`
  }
})
const SchemaField = createSchemaField({
  components: {
    Input,
    FormItem,
  },
});
const form = createForm()

const schema= {
  type: 'object',
  properties: {
    input: {
      type: 'string',
      title: '输入框',
      'x-decorator': 'FormItem',
      'x-component': 'Input',
      'x-component-props': {
        style: {
          width: 240,
        },
      },
       'x-validator':   {
          required: false
       }
    },
  },
};

export default () => (
  <>
   <FormProvider form={form}>
    <SchemaField schema={schema} />
    <FormButtonGroup>
      <Submit onSubmit={form.submit()}>提交</Submit>
    </FormButtonGroup>
  </FormProvider>
  </>
)

What is expected?

预期是

 'x-validator':   {
          required: false
} 

是 false 了,应该不进行校验

Package

@formily/[email protected]


@electroluxcode electroluxcode changed the title [Bug Report] [Bug Report] x-validator 并不能按照预期禁用 [Bug Report] x-validator 并不能按照预期禁用 Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant