1. import React from 'react';
    2. import { Button } from 'antd';
    3. import FormRender, { useForm } from 'form-render';
    4. const schema = {
    5. type: 'object',
    6. properties: {
    7. input1: {
    8. title: '简单输入框',
    9. type: 'string',
    10. required: true,
    11. },
    12. input2: {
    13. title: '简单输入框2',
    14. type: 'boolean',
    15. },
    16. input3: {
    17. title: '简单输入框3',
    18. type: 'string',
    19. required: true,
    20. },
    21. },
    22. };
    23. const Demo = () => {
    24. const form = useForm();
    25. const onFinish = (formData, errorFields) => {
    26. if (errorFields.length > 0) {
    27. alert('errorFields:' + JSON.stringify(errorFields));
    28. } else {
    29. alert('formData:' + JSON.stringify(formData, null, 2));
    30. }
    31. };
    32. return (
    33. <div>
    34. <FormRender form={form} schema={schema} onFinish={onFinish} />
    35. <Button type="primary" onClick={form.submit}>
    36. 提交
    37. </Button>
    38. </div>
    39. );
    40. };
    41. export default Demo;