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

[Field][QUESTION]field.autoUnmount=false,form.item[required=true]动态切换渲染,校验无法通过 #4017

Closed
xmsz opened this issue Jul 26, 2022 · 1 comment · Fixed by alibaba-fusion/field#107
Assignees
Labels
🐞 Bug Something isn't working Next release issues to close in next release

Comments

@xmsz
Copy link

xmsz commented Jul 26, 2022

Component

Field

Feature Description

function App() {
  const field = Field.useField({ autoUnmount: false });
  const [visible, setVisible] = useState(true);
  return (
    <div className="App">
      {JSON.stringify(field.getNames())}
      <Button
        onClick={() => {
          setVisible(!visible);
        }}
      >
        切换item显示
      </Button>
      <Form field={field}>
        {visible && (
          <Form.Item label="文本" name="text" required>
            <Input />
          </Form.Item>
        )}
      </Form>
    </div>
  );
}

https://codesandbox.io/s/fusion-next-template-forked-bgp5vc?file=/src/index.js:209-220

未设置autoUnmount前,如果我把visible设置为false,那么field.getNames就没有了text

但是设置autoUnmount后,无论我怎么切换visible,field.getNames()里就一定有text

我的场景是

  • 因为用到了Setp组件,所以必须autoUnmount设置为false,否则上一步设置的值会消失
  • 我有个输入框是动态渲染的,有些场景下用户没有这个输入框
  • 我这个输入框是required

现在的表现就导致,明明用户不需要输入这个内容,并且前端也没有渲染这个输入框。

但是校验的时候过不去,说用户未填写,因为getNames的时候仍然也有这个key

@YunMeng99 YunMeng99 added the 💡 Feature Request New feature or request label Aug 10, 2023
@YSMJ1994 YSMJ1994 added 🐞 Bug Something isn't working Next release issues to close in next release and removed 💡 Feature Request New feature or request labels Nov 10, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New in DAILY WORK Nov 10, 2023
@seven-lh seven-lh moved this from 🆕 New to 🏗 In progress in DAILY WORK Nov 13, 2023
@YSMJ1994 YSMJ1994 assigned YSMJ1994 and YunMeng99 and unassigned seven-lh and YSMJ1994 Nov 21, 2023
@YunMeng99
Copy link
Contributor

你这个required根据visible去控制吧 因为autoUnmount为false 会保留自动卸载的组件数据。

@YunMeng99 YunMeng99 moved this from 🏗 In progress to 👀 In review in DAILY WORK Dec 4, 2023
@github-project-automation github-project-automation bot moved this from 👀 In review to Ready to release in DAILY WORK Dec 6, 2023
@YSMJ1994 YSMJ1994 moved this from Ready to release to ✅ Done in DAILY WORK Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 Bug Something isn't working Next release issues to close in next release
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants