3.0.15 • Published 4 months ago

mig-schema-form v3.0.15

Weekly downloads
-
License
-
Repository
-
Last release
4 months ago

schema-form-component

This component will render fields dynamically based on openApi schema JSON. Default field validation with ajv is also provided within this package.

Install

  npm install mig-schema-form

Usage

Schema Example:

const userSchema = {
  properties: {
    id: {
      type: "string",
      readOnly: true,
    },
    name: {
      type: "string",
      minLength: 3,
    },
    dob: {
      type: "string",
      format: "date",
    },
    address: {
      type: "string",
      maxLength: 250,
    },
  },
  required: ["name"],
};
    import React from 'react';
    import { SchemaForm, IFieldConfig } from "mig-schema-form";
    import "mig-schema-table/build/index.css";

    const config:{[keyName: string]: IFieldConfig} ={
        "id":{
            hidden:true
        },
        "dob":{
            title:"Date of Birth"
        }
    }

    interface IUserDetailType{}

    const Form=()=>{
        const [userDetail,setUserDetail]= useState();
        const [errorMessages, setErrorMessages] = React.useState<TSchemaFormErrors>();

        const onChangeHandler= React.useCallback(
            (value:IUserDetailType , key:string)=>{
                setUserDetail(value);
                if (errorMessages) {
                    // do somehting
                }
        },[errorMessages])
        return <Form>
            <SchemaForm
                formTitle={"User Details"}
                schema={userSchema}
                onInputChange={onChangeHandler}
                value={userDetail}
                errorMessages={errorMessages}
                config={config}
            />
        </Form>
    }

Component Props

Propdescription
schemaschemaObject to be rendered as a set of fields(example openapi schema).
valueObject, field value will depend on the value of the property of the object.
onInputChangechange handler and will be triggered when typing in the input field. (value: T, key: string) => void.
errorMessagesList of error messages to be shown specifically under the field.
configcustom UI config {keyName: string: IFieldConfig;}.
formTitleProvide a title for a form
formButtonReact Node type and it will render a buttons at the end of fields.
disableFieldsdisable fields conditionally. (boolean)

Config

you can import the type of config from the IFieldConfig.

const config: { [keyName: string]: IFieldConfig } = {};

Development

To to development work, link this repo inside your target project https://docs.npmjs.com/cli/v10/commands/npm-link

3.0.12

5 months ago

3.0.13

5 months ago

3.0.10

7 months ago

3.0.11

7 months ago

3.0.14

4 months ago

3.0.15

4 months ago

3.0.9

9 months ago

3.0.8

9 months ago

2.0.32

1 year ago

3.0.4

12 months ago

3.0.3

1 year ago

3.0.2

1 year ago

3.0.1

1 year ago

3.0.7

11 months ago

3.0.6

11 months ago

3.0.5

11 months ago

2.0.31

1 year ago

2.0.29

1 year ago

2.0.30

1 year ago

2.0.28

1 year ago

2.0.27

1 year ago

2.0.26

1 year ago

2.0.24

1 year ago

2.0.25

1 year ago

2.0.23

1 year ago

2.0.22

1 year ago

2.0.21

1 year ago

2.0.19

1 year ago

2.0.18

1 year ago

2.0.17

1 year ago

2.0.16

1 year ago

2.0.15

1 year ago

2.0.14

1 year ago

2.0.13

1 year ago

2.0.12

1 year ago

2.0.11

1 year ago

2.0.10

1 year ago

2.0.9

1 year ago

2.0.7

1 year ago

2.0.8

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.6

1 year ago

2.0.1

2 years ago

2.0.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago