1. import React from 'react';
    2. import { Button } from 'antd';
    3. import FormRender, { useForm } from 'form-render';
    4. const schema = {
    5. type: 'object',
    6. displayType: 'row',
    7. properties: {
    8. listName2: {
    9. title: '对象数组',
    10. description: '对象数组嵌套功能',
    11. type: 'array',
    12. widget: 'cardList',
    13. items: {
    14. type: 'object',
    15. properties: {
    16. input1: {
    17. title: '简单输入框',
    18. type: 'string',
    19. required: true,
    20. },
    21. select1: {
    22. title: '单选',
    23. type: 'string',
    24. enum: ['a', 'b', 'c'],
    25. enumNames: ['早', '中', '晚'],
    26. },
    27. },
    28. },
    29. },
    30. },
    31. };
    32. // const schema = {
    33. // displayType: 'column',
    34. // type: 'object',
    35. // properties: {
    36. // input1: {
    37. // title: '简单输入框',
    38. // type: 'string',
    39. // required: true,
    40. // },
    41. // select1: {
    42. // title: '单选',
    43. // type: 'string',
    44. // enum: ['a', 'b', 'c'],
    45. // enumNames: ['早', '中', '晚'],
    46. // },
    47. // },
    48. // };
    49. const Demo = () => {
    50. const form = useForm();
    51. const onFinish = (formData, errorFields) => {
    52. if (errorFields.length > 0) {
    53. alert('errorFields:' + JSON.stringify(errorFields));
    54. } else {
    55. alert('formData:' + JSON.stringify(formData, null, 2));
    56. }
    57. };
    58. return (
    59. <div>
    60. <FormRender debug form={form} schema={schema} onFinish={onFinish} />
    61. <Button type="primary" onClick={form.submit}>
    62. 提交
    63. </Button>
    64. </div>
    65. );
    66. };
    67. export default Demo;