1.7.0 β€’ Published 6 months ago

antd-pro-schema-form v1.7.0

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

antd-pro-schema-form

πŸŽ‰πŸŽ‰πŸŽ‰ form item value atomize released!!! See Detail

antd-pro-schema-form based Ant Design, quickly generate interactive forms with Schema configuration.

English | δΈ­ζ–‡ζ–‡ζ‘£

Features

  • Reactive
  • Progressive
  • Schema
  • Group schema
  • Fetch remote data multiple mode
  • Fusion and fission value
  • Test case coverage 99%+

Install

install with npm:

npm install --save-dev antd-pro-schema-form

install with yarn:

yarn add antd-pro-schema-form -dev

install with pnpm:

pnpm add antd-pro-schema-form

Quickstart

normal

import React from 'react';
import { Form, Button } from 'antd';
import SchemaForm, { Schema } from 'antd-pro-schema-form';

export default () => {
  const [formRef] = Form.useForm();

  const schema: Schema = [{
    fieldName: 'title',
    label: 'title',
    type: 'input',
    placeholder: 'please input',
    rules: [{ required: true, message: 'Please input title' }]
  }]
  const onSubmit = () => {
    alert(formRef.current.getFieldsValue());
  };
  return (
    <>
      <SchemaForm form={formRef} schema={schema} />
      <Button onClick={onSubmit}>
        Submit
      </Button>
    </>
  )
}

group schema

import React from 'react';
import { Form, Button } from 'antd';
import SchemaForm, { Schema, SchemaGroups } from 'antd-pro-schema-form';

export default () => {
  const [formInstance] = Form.useForm();

  const schema: Schema = {
    title: {
      fieldName: 'title',
      label: 'title',
      type: 'input',
      placeholder: 'please input',
      rules: [{ required: true, message: 'Please input title' }]
    }
  };
  const schemaGroups: SchemaGroups = [{
    list: [
      'title',
    ]
  }];

  const onSubmit = () => {
    alert(JSON.stringify(formInstance.getFieldsValue()));
  };
  return (
    <>
      <SchemaForm form={formInstance} schema={schema} schemaGroups={schemaGroups} />
      <Button onClick={onSubmit}>
        Submit
      </Button>
    </>
  )
}

Advanced

Convert form item value when initialize or submit

  import React, { useRef, useEffect } from 'react';
  import SchemaForm, { RefCurrent, Schema } from 'antd-pro-schema-form';
  import dayjs from 'dayjs';
  import { Button, Form } from 'antd';

  export default () => {
    const formRef = useRef<RefCurrent>();

    const schema: Schema = [{
      fieldName: 'date',
      label: 'date',
      type: 'datePicker',
      fusion(value) {
        // transform value when setFieldsValue
        return dayjs(value);
      },
      fission(value) {
        // transform value when form submit or getFieldsValue
        return value.format('YYYY-MM-DD HH:mm:ss');
      }
    }];

    useEffect(() => {
      if (!formRef.current) return;
      formRef.current.setFieldsValue({
        date: '2023-08-08',
      })
    }, [formRef]);

    const submit = () => {
      // the same as formInstance.getFieldsValue()
      alert(JSON.stringify(formRef.current.getFieldsValue()));
    };

    return (
      <>
        <SchemaForm enableValueAtomize ref={formRef} schema={schema} />
        <Button type="primary" onClick={submit}>submit</Button>
      </>
    )
  }

Ducumentation

see https://drdevelop.github.io/antd-pro/index.html#/schema-form/readme

1.7.0

6 months ago

1.6.1

7 months ago

1.6.0

7 months ago

1.5.3

7 months ago

1.5.2

7 months ago

1.5.1

7 months ago

1.5.0

7 months ago

1.4.0

8 months ago

1.3.0

8 months ago

1.2.6

8 months ago

1.2.5

8 months ago

1.2.4

8 months ago

1.2.3

8 months ago

1.2.2

8 months ago

1.2.1

9 months ago

1.2.0

9 months ago

1.1.0

9 months ago

1.0.0

9 months ago

1.0.0-rc.34

9 months ago

1.0.0-rc.33

9 months ago

1.0.0-rc.32

9 months ago

1.0.0-rc.31

9 months ago

1.0.0-rc.30

9 months ago

1.0.0-rc.29

9 months ago

1.0.0-rc.28

9 months ago

1.0.0-rc.27

9 months ago

1.0.0-rc.26

9 months ago

1.0.0-rc.25

9 months ago

1.0.0-rc.24

9 months ago

1.0.0-rc.23

9 months ago

1.0.0-rc.22

9 months ago

1.0.0-rc.19

9 months ago

1.0.0-rc.18

9 months ago

1.0.0-rc.17

9 months ago

1.0.0-rc.16

9 months ago

1.0.0-rc.15

9 months ago

1.0.0-rc.14

9 months ago

1.0.0-rc.13

9 months ago

1.0.0-rc.12

9 months ago

1.0.0-rc.11

9 months ago

1.0.0-rc.10

9 months ago

1.0.0-rc.9

9 months ago

1.0.0-rc.8

9 months ago

1.0.0-rc.7

9 months ago

1.0.0-rc.6

9 months ago

1.0.0-rc.5

9 months ago

1.0.0-rc.4

9 months ago

1.0.0-rc.3

9 months ago

1.0.0-rc.2

9 months ago

1.0.0-rc.1

9 months ago

1.0.0-rc.0

9 months ago