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] @formily/antd-v5 FormItem 的 asterisk 属性部分情况下逻辑不正确 #3820

Closed
1 task done
StephenPCG opened this issue May 15, 2023 · 1 comment · Fixed by formilyjs/antd#13
Closed
1 task done

Comments

@StephenPCG
Copy link

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

Reproduction link

.

Steps to reproduce

表单定义 JSON Schema 如下:

const schema = {
    type: "string",
    required: true,
    "x-decorator": "FormItem",
    "x-decorator-props": { asterisk: false }, 
    "x-component": "Input",
}

What is expected?

由于业务对 UI 的需求,希望无论字段是否必填,都不显示 *
这里,期望当给 FormItem 提供了 asterisk 属性时,应当尊重该属性。

What is actually happening?

按照目前 FormItem 的实现,只要 requiredtrue,就强制显示 *,而忽略 props.asterisk 的设置。

目前 FormItem 的代码如下:

https://github.com/formilyjs/antd/blob/master/packages/components/src/form-item/index.tsx#L315-L323

      const takeAsterisk = () => {
        if (field.required && field.pattern !== 'readPretty') {
          return true
        }
        if ('asterisk' in props) {
          return props.asterisk
        }
        return false
      }

应当交换两个 if 的顺序,当 props 中包含 asterisk 时,尊重 props,否则才自动设置。

Package

@formily/antd-v5@1.1.0-beta.2


@yiyunwan
Copy link
Collaborator

可以提交个pr,我今晚发布

StephenPCG pushed a commit to StephenPCG/formilyjs-antd-v5 that referenced this issue May 15, 2023
yiyunwan pushed a commit to formilyjs/antd that referenced this issue May 15, 2023
alibaba/formily#3820

Co-authored-by: Zhang Cheng <chengzhang@natureself.cn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants