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

formList 组件内新增一项,会有问题 #3223

Closed
Lyrics1 opened this issue Nov 21, 2024 · 1 comment
Closed

formList 组件内新增一项,会有问题 #3223

Lyrics1 opened this issue Nov 21, 2024 · 1 comment

Comments

@Lyrics1
Copy link

Lyrics1 commented Nov 21, 2024

tdesign-react 版本

1.10.0

重现链接

No response

重现步骤

https://stackblitz.com/edit/react-kw3fgf?file=src%2Fdemo.tsx
打开上方链接,然后把下面这个代码复制进去就能复现

mport React from 'react';
import { Form, Input, Button, Select } from 'tdesign-react';
import { MinusCircleIcon } from 'tdesign-icons-react';

const { FormItem, FormList } = Form;

const provinceOptions = [
{ label: '北京', value: 'bj', a: 1 },
{ label: '上海', value: 'sh', a: 2 },
{ label: '广州', value: 'gz', a: 3 },
{ label: '深圳', value: 'sz', a: 4 },
];

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

function onSubmit() {
const allFields = form.getFieldsValue(true);
console.log('allFields', allFields);
}

return (



{(fields, { add, remove }) => (
<>
{fields.map(({ key, name, ...restField }, index) => (

<FormItem
{...restField}
name={[name, 'province']}
label="省份"
rules={[{ required: true, type: 'error' }]}
>


<FormItem
{...restField}
name={[name, 'a']}
label="省份"
rules={[{ required: true, type: 'error' }]}
>



<MinusCircleIcon
size="20px"
style={{ cursor: 'pointer' }}
onClick={() => remove(name)}
/>
<Button
theme="default"
variant="dashed"
onClick={() =>
add({ province: 'bj', area: 'tzmax' }, index + 1)
}
>
Add field


<FormItem style={{ marginLeft: 100 }}>
<Button
theme="default"
variant="dashed"
onClick={() =>
add({ province: 'sh', area: 'tzmax', a: '11' })
}
>
Add field



))}
<FormItem style={{ marginLeft: 100 }}>
<Button
theme="default"
variant="dashed"
onClick={() => add({ province: 'sh', area: 'tzmax', a: '11' })}
>
Add field


</>
)}

<FormItem style={{ marginLeft: 100 }}>

提交

<Button type="reset" style={{ marginLeft: 12 }}>
重置



);
}

期望结果

内部新增按钮,可以新增省份为上海

实际结果

No response

框架版本

No response

浏览器版本

No response

系统版本

No response

Node版本

No response

补充说明

import React from 'react';
import { Form, Input, Button, Select } from 'tdesign-react';
import { MinusCircleIcon } from 'tdesign-icons-react';

const { FormItem, FormList } = Form;

const provinceOptions = [
{ label: '北京', value: 'bj', a: 1 },
{ label: '上海', value: 'sh', a: 2 },
{ label: '广州', value: 'gz', a: 3 },
{ label: '深圳', value: 'sz', a: 4 },
];

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

function onSubmit() {
const allFields = form.getFieldsValue(true);
console.log('allFields', allFields);
}

return (



{(fields, { add, remove }) => (
<>
{fields.map(({ key, name, ...restField }, index) => (

<FormItem
{...restField}
name={[name, 'province']}
label="省份"
rules={[{ required: true, type: 'error' }]}
>


<FormItem
{...restField}
name={[name, 'a']}
label="省份"
rules={[{ required: true, type: 'error' }]}
>



<MinusCircleIcon
size="20px"
style={{ cursor: 'pointer' }}
onClick={() => remove(name)}
/>
<Button
theme="default"
variant="dashed"
onClick={() =>
add({ province: 'bj', area: 'tzmax' }, index + 1)
}
>
Add field


<FormItem style={{ marginLeft: 100 }}>
<Button
theme="default"
variant="dashed"
onClick={() =>
add({ province: 'sh', area: 'tzmax', a: '11' })
}
>
Add field



))}
<FormItem style={{ marginLeft: 100 }}>
<Button
theme="default"
variant="dashed"
onClick={() => add({ province: 'sh', area: 'tzmax', a: '11' })}
>
Add field


</>
)}

<FormItem style={{ marginLeft: 100 }}>

提交

<Button type="reset" style={{ marginLeft: 12 }}>
重置



);
}

Copy link
Contributor

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

@Lyrics1 Lyrics1 closed this as completed Nov 21, 2024
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

No branches or pull requests

1 participant