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]Field 表单辅助工具设置值不生效 bug #4525

Closed
Liting1 opened this issue Nov 14, 2023 · 7 comments · Fixed by alibaba-fusion/field#105
Closed

[Field]Field 表单辅助工具设置值不生效 bug #4525

Liting1 opened this issue Nov 14, 2023 · 7 comments · Fixed by alibaba-fusion/field#105
Assignees
Labels
🐞 Bug Something isn't working Next release issues to close in next release

Comments

@Liting1
Copy link

Liting1 commented Nov 14, 2023

注:@alifd/next 包 version 1.26.31 有问题,
以前的旧版本包就没有 例如 1.26.18 版本就是正常的

Component

Field

import React from "react";
import { Form, Field, Button, Input } from '@alifd/next';
const FormTest = () => {
  const filed = Field.useField({
    parseName: true, autoUnmount: false, values: {
      one: [],
      two: { code: '33' }
    }
  });
  const clickHandle = () => {
    filed.setValues({
      one: [
        [{ b: { name: 'zhangsan', age: 27 } }],
      ], two: { code: '555' }
    })
  }
  const clickHandle2 = () => {
    // debugger;
    filed.setValues({
      one: [
        [{ b: null }], // 设置数据的值失败
      ],
      two: '' // 设置数据失败
    })
  }
  console.log(filed.getValues());

  return <div>
    <Form field={filed}>
      <Form.Item label="one-1">
        <Input type="text" {...filed.init(`one.0.0.b.name`)} />
      </Form.Item>
      <Form.Item label="one-2">
        <Input type="text" {...filed.init(`one.0.0.b.age`)} />
      </Form.Item>
      <Form.Item label="one-3">
        <Input type="text" {...filed.init(`two.code`)} />
      </Form.Item>
      <Button onClick={clickHandle}>按钮 1</Button>
      <Button onClick={clickHandle2}>按钮 2</Button>
    </Form>
  </div>
}
export default FormTest;

以上代码就能复现 先点按钮1 , 再点按钮2 就能看到

@YSMJ1994 我目测原因出在 @alifd/field 这个包的这个地方
image

@Liting1
Copy link
Author

Liting1 commented Nov 14, 2023

image
点击按钮1 时正常设置值,点击按钮2的时候设置值就没有生效

@YSMJ1994
Copy link
Contributor

按照目前的 parseName=true 对于setValues的设计 ( shallow merge and keep old field values ),你这个情况是符合预期的,清空数据可以使用 reset() 方法

@Liting1
Copy link
Author

Liting1 commented Nov 14, 2023

@YSMJ1994 但是旧版本是可以这么设置的, 这样不是会出现很多问题吗

@YSMJ1994
Copy link
Contributor

@YSMJ1994 但是旧版本是可以这么设置的, 这样不是会出现很多问题吗

近期的版本确实是有不一致的问题,我看一下

@YSMJ1994
Copy link
Contributor

@Liting1 排查到的问题是以前的逻辑针对非undefined值会直接使用新的值来替换,你设置的 null 和 "" 正好符合了这个规则,所以覆盖了原有field的值,最近一次改动调整了这块逻辑,通过hasIn判断就走进了错误的逻辑。
已经了解到了这个问题,我们将在下一个迭代中修复这个问题,感谢你的反馈。

@YSMJ1994 YSMJ1994 added 🐞 Bug Something isn't working Next release issues to close in next release labels Nov 14, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New in DAILY WORK Nov 14, 2023
@YSMJ1994 YSMJ1994 self-assigned this Nov 15, 2023
@YSMJ1994 YSMJ1994 moved this from 🆕 New to 👀 In review in DAILY WORK Nov 21, 2023
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in DAILY WORK Nov 22, 2023
@YSMJ1994
Copy link
Contributor

@YSMJ1994
Copy link
Contributor

Fixed at @alifd/field@1.6.7

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.

2 participants