Skip to content

Conversation

@RylanBot
Copy link
Collaborator

@RylanBot RylanBot commented Dec 30, 2025

🤔 这个 PR 的性质是?

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

🔗 相关 Issue

💡 需求背景和解决方案

测试代码存档
import React from 'react';
import type { FormProps } from 'tdesign-react';
import { Button, Form, Input, MessagePlugin, Space } from 'tdesign-react';

const { FormItem } = Form;

export default function BaseForm() {
  const [form] = Form.useForm();

  const onReset: FormProps['onReset'] = (e) => {
    console.log(e);
    MessagePlugin.info('重置成功');
  };

  const getFieldsValueWithTrue = () => {
    // 设置一个不在 FormItem 中定义的字段到store中
    form.setFieldsValue({
      hiddenField: '这是一个不在FormItem中的隐藏字段',
    });

    const allValues = form.getFieldsValue(true);
    console.log('所有字段值(包括store中的隐藏字段):', allValues);

    // 验证 hiddenField 是否存在
    if (allValues.hiddenField) {
      MessagePlugin.success(`验证成功!获取到隐藏字段: ${allValues.hiddenField}`);
    } else {
      MessagePlugin.error('验证失败!未获取到隐藏字段');
    }
  };

  const getFieldsValueWithName = () => {
    // 设置一个不在 FormItem 中定义的字段到store中
    form.setFieldsValue({
      hiddenField: '这是一个不在FormItem中的隐藏字段',
    });

    // 使用 nameList 获取指定字段的值(包括隐藏字段)
    const specificValues = form.getFieldsValue(['name', 'hiddenField']);
    console.log('指定字段值 (name, hiddenField):', specificValues);

    // 验证 hiddenField 是否存在
    if (specificValues.hiddenField) {
      MessagePlugin.success(`验证成功!获取到隐藏字段: ${specificValues.hiddenField}`);
    } else {
      MessagePlugin.error('验证失败!未获取到隐藏字段');
    }
  };

  const getFieldValue = () => {
    // 设置一个不在 FormItem 中定义的字段到store中
    form.setFieldsValue({
      hiddenField: '这是一个不在FormItem中的隐藏字段',
    });

    // 使用 getFieldValue 获取单个隐藏字段值
    const hiddenValue = form.getFieldValue('hiddenField');
    console.log('单个字段值 (hiddenField):', hiddenValue);

    // 验证 hiddenField 是否存在
    if (hiddenValue) {
      MessagePlugin.success(`验证成功!获取到隐藏字段: ${hiddenValue}`);
    } else {
      MessagePlugin.error('验证失败!未获取到隐藏字段');
    }
  };

  return (
    <Form form={form} onReset={onReset}>
      <FormItem label="姓名" name="name">
        <Input />
      </FormItem>
      <FormItem>
        <Space>
          <Button onClick={getFieldsValueWithTrue}> getFieldsValueWithTrue </Button>
          <Button onClick={getFieldsValueWithName}>getFieldsValueWithName</Button>
          <Button onClick={getFieldValue}>getFieldValue</Button>
          <Button type="reset" theme="default">
            重置
          </Button>
        </Space>
      </FormItem>
    </Form>
  );
}

📝 更新日志

  • 本条 PR 不需要纳入 Changelog

tdesign-react

  • feat(Form): 支持 getFieldsValuegetFieldValue 返回未渲染的数值

@tdesign-react/chat

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

@tdesign-bot
Copy link
Collaborator

tdesign-bot commented Dec 30, 2025

TDesign Component Site Preview Open

Component Preview
tdesign-react 完成
@tdesign-react/chat 完成

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 30, 2025

  • tdesign-react-demo

    npm i https://pkg.pr.new/Tencent/tdesign-react@4050
    
    npm i https://pkg.pr.new/Tencent/tdesign-react/@tdesign-react/chat@4050
    

commit: e9caedf

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 this pull request may close these issues.

3 participants