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

[Form] FormApi.setValues 行为与文档不符 #885

Open
zixuan945 opened this issue Jun 5, 2022 · 2 comments
Open

[Form] FormApi.setValues 行为与文档不符 #885

zixuan945 opened this issue Jun 5, 2022 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@zixuan945
Copy link

Which Component 出现bug的组件

  • Form

semi-ui version

  • latest

Expected result 期望的结果是什么

  • 根据文档,第二个参数中的 isOverride 默认为 false,默认情况下只会从newValues中取 Form 中已存在的 field 的值更新到formState.values中,我的理解是合并newValues 至 formStatus.values中

Actual result 实际的结果是什么

  • 直接设置formStatus.values为 newValues,不存在的值直接被 reset 为空值

Steps to reproduce 复现步骤

If your reproduction scene is complicated, you can list the reproduction steps here

如果你的复现场景比较复杂,可以在这里列出复现的步骤

  • 见下述示例

Reproducible code 复现代码

  • You can paste a minimal reproducible code, preferably runnable in the code editing area of Semi official website
    借用官网上例子Hooks的使用稍做更改。期待行为是只更新name而保留test,实际上test字段被直接reset
import React from 'react';
import { useFormApi, Form, Button } from '@douyinfe/semi-ui';

class UseFromApiDemo extends React.Component {
    constructor() { super(); }
    render() {
        const ComponentUsingFormApi = () => {
            const formApi = useFormApi();
            const change = () => {
                formApi.setValues({'name':Math.random()});
            };
            return (
                <Button onClick={change}>ChangeName By【formApi】</Button>
            );
        };
        return (
            <Form>
                <Form.Input field='name' initValue='mike'></Form.Input>
                <Form.Input field='test' initValue='testA'></Form.Input>
                <ComponentUsingFormApi />
            </Form>
        );
    }
}

  • You can also use Codesandbox to create a minimal reproduction scene use Semi template

Reproducible Codesandbox link: https://codesandbox.io

  • Or, if your scene is more complex, you can use other templates to create a reproducible scene

Reproducible Codesandbox link: https://codesandbox.io

Additional information 补充说明

@zixuan945 zixuan945 added the bug Something isn't working label Jun 5, 2022
@zixuan945
Copy link
Author

debug了一下发现是下述这里value为undefined所致,加了个判断后行为正常了

field.fieldApi.setValue(value, opts);

value&&field.fieldApi.setValue(value, opts);

@xmsz-stu
Copy link

情况如何

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants