1. import React from 'react';
    2. import { Button } from 'antd';
    3. import FormRender, { useForm } from 'form-render';
    4. const schema = {
    5. displayType: 'row',
    6. labelWidth: 120,
    7. type: 'object',
    8. properties: {
    9. input1: {
    10. title: '简单输入框',
    11. description:
    12. 'sdfasdgdsgfdsgfsdfgssdgdsgfdsgfsdfgssdgdsgfdsgfsdfgsdfgsdfgfghfghfghfgh',
    13. type: 'string',
    14. required: true,
    15. },
    16. input2: {
    17. title: '简单输入框2',
    18. type: 'boolean',
    19. },
    20. daaa: {
    21. title: 'daa',
    22. type: 'string',
    23. format: 'date',
    24. props: {
    25. showTime: true,
    26. format: 'dateTime',
    27. },
    28. },
    29. daaa2: {
    30. title: 'daa2',
    31. type: 'string',
    32. format: 'time',
    33. },
    34. daaa3: {
    35. title: 'daa3',
    36. type: 'range',
    37. format: 'date',
    38. },
    39. input3: {
    40. title: '图片',
    41. type: 'string',
    42. format: 'image',
    43. required: true,
    44. },
    45. input4: {
    46. title: 'url',
    47. type: 'string',
    48. format: 'url',
    49. required: true,
    50. },
    51. },
    52. };
    53. const Demo = () => {
    54. const form = useForm();
    55. const onFinish = (formData, errorFields) => {
    56. if (errorFields.length > 0) {
    57. alert(
    58. 'errorFields:' +
    59. JSON.stringify(errorFields) +
    60. '\nformData:' +
    61. JSON.stringify(formData, null, 2)
    62. );
    63. } else {
    64. alert('formData:' + JSON.stringify(formData, null, 2));
    65. }
    66. };
    67. return (
    68. <div>
    69. <FormRender
    70. debugCss={false}
    71. form={form}
    72. schema={schema}
    73. onFinish={onFinish}
    74. />
    75. <Button type="primary" onClick={form.submit}>
    76. 提交
    77. </Button>
    78. </div>
    79. );
    80. };
    81. export default Demo;