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

Feature: 希望动态表单支持无限嵌套写法 #111

Open
LiYanTaogithub opened this issue Jun 13, 2021 · 1 comment
Open

Feature: 希望动态表单支持无限嵌套写法 #111

LiYanTaogithub opened this issue Jun 13, 2021 · 1 comment

Comments

@LiYanTaogithub
Copy link

LiYanTaogithub commented Jun 13, 2021

Description

希望动态表单支持无限嵌套写法

function Demo() {
    const config = {
        fields:[
            {
                name: 'test',
                field: {
                    type: 'input',
                    props: {
                        placeholder: '请输入',
                        style: {
                            width: 120,
                        },
                    },
                },
            },
            { 
                name: 'outer',
                label: '外层表单',
                isList: true,
                container: 'Card',
                field: {
                    type: 'dynamicdepfieldcomp',
                    props: {
                        fields: [
                            {
                                name: '嵌套表单',
                                label: 'inner',
                                isList: true,
                                container: 'Card',
                                field: {
                                    type: 'dynamicdepfieldcomp',
                                    props:{
                                        fields: [
                                            {
                                                name: 'test',
                                                label: 'test',
                                                field: 'input',
                                            },
                                        ],
                                    },
                                },
                            },
                            {
                                name: 'q',
                                rules: [{ required: true, message: 'type something' }],
                                field: {
                                    type: 'input',
                                    props: {
                                        placeholder: '请输入',
                                        style: {
                                            width: 120,
                                        },
                                    },
                                },
                            },
                            {
                                name: 'fruilt',
                                label: '水果',
                                field: {
                                    type: 'select',
                                    props: {
                                        placeholder: '请输入',
                                        style: {
                                            width: 120,
                                        },
                                    },
                                },
                                remoteSource: {
                                    init: false,
                                    url:
                      'https://run.mocky.io/v3/a435a830-a2b3-49ce-bc6b-40298ba57bcb',
                                    method: 'GET',
                                    converter: ({ data }) => {
                                        return data.map((item) => {
                                            return {
                                                text: item.text,
                                                value: item.value,
                                            };
                                        });
                                    },
                                },
                            },
                            {
                                name: 'goods',
                                label: '货物',
                                initialValue: 'oil',
                                initialSource: [
                                    {
                                        label: '石油',
                                        value: 'oil',
                                    },
                                    {
                                        label: '煤',
                                        value: 'coal',
                                    },
                                ],
                                field: {
                                    type: 'select',
                                    props: {
                                        placeholder: '请输入',
                                        style: {
                                            width: 120,
                                        },
                                    },
                                },
                            },
                        ],
                    },
                },
            },
            {
                label: ' ',
                colon: false,
                render: {
                    type: 'button',
                    props: {
                        htmlType: 'submit',
                        type: 'primary',
                        children: 'submit',
                    },
                },
            },
            {
                label: ' ',
                colon: false,
                render: {
                    type: 'button',
                    props: {
                        onClick: () => {
                            this.ref.current.validateFields().then((values) => {
                                console.log('表单值: ', values);
                            });
                        },
                        children: 'api提交',
                    },
                },
            },
        ],
    };
    return (
        <Form
            initialValues={{ radiogroup: 'peach' }}
            onFinish={(values) => {
                console.log('Success:', values);
            }}
            {...config}
        />
    );
}

Solution

@yulongcs
Copy link

正好需要这个场景,求大佬更新下

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

2 participants