formily icon indicating copy to clipboard operation
formily copied to clipboard

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

Open electroluxcode opened this issue 1 year ago • 0 comments

  • [ ] 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 avatar Sep 05 '24 15:09 electroluxcode

🦋 Changeset detected

Latest commit: 467e872da7d2be532e05f21dd01c2e72484ff2a2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
solid-js Patch
test-integration Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Sep 01 '24 16:09 changeset-bot[bot]

Pull Request Test Coverage Report for Build 10655705996

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.342%

Totals Coverage Status
Change from base Build 10586064173: 0.0%
Covered Lines: 4196
Relevant Lines: 4429

💛 - Coveralls

coveralls avatar Sep 01 '24 16:09 coveralls

Actually I just tested, and autocompletion will work as long as the app already imports the default html somewhere first. So this change is not needed for that.

This does make it easy to write things like export * from 'solid-js/html' though, so I'd say keep it.

trusktr avatar Sep 01 '24 19:09 trusktr