# react-build-form

> Make dynamic forms. It uses antd ui library, formik, yup, dayjs

Latest version **1.3.15** (published 2024-05-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-build-form
pnpm add react-build-form
yarn add react-build-form
bun add react-build-form
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.15 |
| Published | 2024-05-31 |
| First published | 2024-03-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 152.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Elvin Murshudlu\ |
| Maintainers | elvinmurshudlu_ |
| Keywords | form, react-form, react-form-antd, form-builder, builder, build, build-form, form-build |

## Links

- npm: https://www.npmjs.com/package/react-build-form
- npm.io page: https://npm.io/package/react-build-form

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.3.15 (latest) — 2024-05-31
- 1.3.14 — 2024-05-23
- 1.3.13 — 2024-05-10
- 1.3.12 — 2024-04-25
- 1.3.11 — 2024-04-25
- 1.3.10 — 2024-04-24
- 1.3.9 — 2024-04-24
- 1.3.8 — 2024-04-24
- 1.3.7 — 2024-04-24
- 1.3.6 — 2024-04-24
- 1.3.5 — 2024-04-24
- 1.3.41 — 2024-04-24
- 1.3.4 — 2024-04-24
- 1.3.3 — 2024-04-24
- 1.3.2 — 2024-04-24
- … 44 more at https://npm.io/package/react-build-form/versions

## README

# What is this?
 Build dynamic , complex forms more easy.

# Requirements.
 For components - ANTD ui library,
 Form - formik,
 Validation - Yup,
 Bootstrap for grid system (It will be removed next updates)

# Installation
 `npm i react-build-form`
  add : `@import "bootstrap/scss/bootstrap"` to your scss file

# Usage

    ```
    import {FormBuilder} from "react-build-form"
 
    export default function YourComponent(){
        function doSmth(values){
            ....
        }

        return <FormBuilder inputScheme={[
               {
                    label:'Username',
                    field:'login',
                    type:"text",
                    col:"col-12",
                    initialValue:null,
                    validation:Yup.string().required(),
                    required:true,
                    props:{
                        placeholder:'Username or email',
                        size:'large',
                        prefix:<UsernameIcon/>,
                        style:{
                            padding:"12px"
                        }
                    }

                }
            ]}
             onSubmit={(values)=>doSmth(values)} 
             button={{
                title:"Verify",
                props: {
                    size:'large',
                    style:{
                        width:"100%",
                        backgroundColor:'#7F56D9',
                        color:'white',
                        padding:"14px",
                        height:"auto"
                    },
                    className:'mb-3'
                }
            }}  />
    }
    ```
# Explanation
1. inputScheme
   1.  label : label for Input
   2.  field : write value's key (Above example values is {login:'any value you wrote'})
   3.  type : there is 9 types:
      1. text : it renders simple Input component in ANTD
      2. text-area : it renders TextArea component  in ANTD
      3. selection : it renders Select component  in ANTD
      4. tree-select : it renders Tree-select component  in ANTD
      5. switch : it renders switch component  in ANTD
      6. date : it renders Date component  in ANTD
      7. range : it renders Range component (Date component in range) in ANTD
      8. upload : it renders Upload component in ANTD and all uploaded files store in key
      9. custom : any custom component you want can render
      10. container type : responsible for grouping inputs in one component :
      ```
       {
            type:'container',
            component:(nodesComingFromSchema)=><YourContainerComponent>{nodesComingFromSchema}</YourContainerComponent>,
            schema:[
                {
                    type:'text',
                    field:'test',
                    initialValue:null,
                    validation:Yup.string(),
                    col:'col-12',
                    
                }
            ]
        },
      ```
      then test input will placed in YourContainerComponent

   4. col : it is bootstap column clases for  (col-1 , col-md-1 , etc.)
   5. initialValue : it is initial value of form field
   6. validation : only accept yup validation schema
   9. required: this field is responsible red star, if required you can easily add red star
   10. props : it has all types of ANTD component props
   11. linear : default value is false | if true then input field items ordered horizontally
   12. showOn : receives array , first index of array is null or string[] (other fields name  which depends on this fields) ,second index is callback that return boolen if true then shows othwerwise not shown
```
[{
            field:"other",
            initialValue:null,
            validation:Yup.string().nullable(),
            col: 'col-12 col-md-6 col-lg-4',
            type:'text',
            
        },
    {
            field:"parent",
            initialValue:null,
            validation:Yup.string().nullable(),
            col: 'col-12 col-md-6 col-lg-4',
            type:'text',
            
        },
        {
            field:'children',
            label:"Təsdiq edən şəxs",
            type:"text",
            required:true,
            initialValue:null,
            validation:Yup.number().nullable(),
            col:'col-12 col-md-6 col-lg-4',
            showOn:[['parent'],(values)=>{
                return  values[0] === condition
            }],
           
        },]

```
 meaning : children input only depends on parent and values is array ([parent]) first index is parents value,
 if you want depends on both parent and other
 ```
 {
            field:'children',
            label:"Təsdiq edən şəxs",
            type:"text",
            required:true,
            initialValue:null,
            validation:Yup.number().nullable(),
            col:'col-12 col-md-6 col-lg-4',
            showOn:[['parent','other'],([parentVal,otherVal])=>{
                return  ...your condition
            }],
           
        }
 ```
 13. calculateValue : it means calculate inputs value depends on other inputs value
     ```
     [
    {
            field:"parent",
            initialValue:null,
            validation:Yup.string().nullable(),
            col: 'col-12 col-md-6 col-lg-4',
            type:'text',
            
        },
        {
            field:'children',
            label:"Təsdiq edən şəxs",
            type:"text",
            required:true,
            initialValue:null,
            validation:Yup.number().nullable(),
            col:'col-12 col-md-6 col-lg-4',
            calculateValue:[['parent'],([parentValue])=>{
                return  parentValue + ' world '
            }],
           
        },]

    ```
    meaning if parents value is (hello)  then children value is 'hello world'
2. onSubmit : this is function called after submit button click and all field is valid
3. button :
    1. title : button text
    2. props: similar to ANTD button props
4. customButtons : you can add more buttons to form and receives array
     ```
     customButtons={[
                     (values, customSubmit)=>{
                        return <Button>Second button</Button>
                     }
                     ]}
     ``` 
    values is : form's values
    customSubmit : validates form if valid return true otherwise false

# Author 
  [@elvinmurshudlu](https://www.linkedin.com/in/elvin-murshudlu-2a24a7217/)

---
_Source: https://npm.io/package/react-build-form · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
