tdesign-react icon indicating copy to clipboard operation
tdesign-react copied to clipboard

[InputAdornment] append为Select时,有什么办法可以在Form中收集到Select的值吗?

Open chenkang-noob opened this issue 1 year ago • 1 comments

这个功能解决了什么问题

InputAdornment的append为Select时,在Form表单中无法收集到Select选择的值。感觉不是很方便

你建议的方案是什么

InputAdornment的append为Select时,在Form表单中可以收集到Select选择的值

chenkang-noob avatar Oct 30 '24 08:10 chenkang-noob

👋 @chenkang-noob,感谢给 TDesign 提出了 issue。 请根据 issue 模版确保背景信息的完善,我们将调查并尽快回复你。

github-actions[bot] avatar Oct 30 '24 08:10 github-actions[bot]

import React, { useState } from 'react';
import { Button, Form, Input, InputAdornment, Select } from 'tdesign-react';

const { FormItem } = Form;

export default function BaseForm() {
  const [form] = Form.useForm();
  const [suffix, setSuffix] = useState('.com');

  const DomainSelect = (
    <Select
      autoWidth
      options={['.com', '.cn'].map((value) => ({ label: value, value }))}
      value={suffix}
      onChange={(value) => setSuffix(value as string)}
    />
  );

  return (
    <Form form={form}>
      <FormItem name="domain">
        <InputAdornment append={DomainSelect}>
          <Input />
        </InputAdornment>
      </FormItem>
      <FormItem>
        <Button
          onClick={() => {
            const formValues = form.getFieldsValue(true);
            console.log({
              ...formValues,
              suffix, // 手动拼接
            });
          }}
        >
          getValue
        </Button>
      </FormItem>
    </Form>
  );
}

RylanBot avatar Nov 27 '25 11:11 RylanBot