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

表单项的id带有#时,表单没办法动态隐藏字段 #1455

Open
Yojay97 opened this issue Dec 28, 2023 · 3 comments
Open

表单项的id带有#时,表单没办法动态隐藏字段 #1455

Yojay97 opened this issue Dec 28, 2023 · 3 comments
Assignees

Comments

@Yojay97
Copy link

Yojay97 commented Dec 28, 2023

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

  • react:18.2.0
  • form-render:2.2.13
  • table-render:
  • antd:5.8.2

2.问题描述(Bug description)
我有一个表单项会根据另外一个表单项的值进行联动,来决定是否隐藏。我发现这个隐藏只在初始化表单的时候有作用,初始化完表单后,切换会影响到隐藏的表单项值时,就不起作用了。

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

const schema = {
  // ...
}

我是手机敲的,实在不好意思,省略一些东西
我的hidden是这样写的
“hidden”: “ {{formData[‘select#type’] !== ‘a’}} ”
我的那个下拉框因为业务需要,所以id是带#号的
4.最小复现 demo(Reproduction demo)

form-render demo https://codesandbox.io/s/unruffled-flower-jl78h
table-render demo https://codesandbox.io/s/sweet-euler-bdoty
fr-generator demo https://codesandbox.io/s/s13sh

@Yojay97
Copy link
Author

Yojay97 commented Dec 28, 2023

我补充一下我的测试代码

import FormRender, {useForm} from "form-render";
import ProCard from "@ant-design/pro-card";

const schema =  {
  type: 'object',
  properties: {
    input: {
      title: '输入框',
      type: 'string',
      widget: 'input',
      hidden: "{{ formData['select#type'] === 'a' }}"
    },
    select: {
      title: '下拉框',
      type: 'string',
      widget: 'select',
      props: {
        options: [
          { label: '早', value: 'a' },
          { label: '中', value: 'b' },
          { label: '晚', value: 'c' }
        ]
      }
    }
  }
};

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

  const onFinish = (formData) => {
    console.log('formData:', formData);
  };

  schema.properties['select#type'] = schema.properties.select;
  
  return (
    <ProCard>
      <FormRender
        form={form}
        schema={schema}
        onFinish={onFinish}
        maxWidth={360}
        footer={true}
        initialValues={{'select#type': 'b'}}
      />
    </ProCard>

  );
}

@Yojay97
Copy link
Author

Yojay97 commented Dec 28, 2023

动画

@lhbxs
Copy link
Collaborator

lhbxs commented Jan 5, 2024

你们的 key 怎么这么奇怪,不按套路出牌啊。

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

No branches or pull requests

2 participants