2.5.4 • Published 2 years ago

reactjs-form-builder v2.5.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

reactjs-form-builder

React Js Form Builder

NPM JavaScript Style Guide

Install

npm install --save reactjs-form-builder
Field TypesAttributes
Texttype: textreadOnly: true/false, placeholder: String,required: true/false,requireMessage: "Custom message for require",min: Integer, max: Integer
Numbertype: numberreadOnly: true/false, placeholder: String,required: true/false,requireMessage: "Custom message for require",min: Integer, max: Integer
Textareatype: textareareadOnly: true/false, placeholder: String,required: true/false,requireMessage: "Custom message for require",min: Integer, max: Integer
Selecttype: selectplaceholder: String,options:{"label":"Apple","value":"apple"},{"label":"Banana","value":"banana"} ,required: true/false,requireMessage: "Custom message for require", multiple: true/false, autofocus: true/false
Checkboxtype: checkboxplaceholder:String, options:{"label":"Apple","value":"apple"},{"label":"Banana","value":"banana"} ,required: true/false,requireMessage: "Custom message for require"
Radiotype: radioplaceholder:String, options:{"label":"Apple","value":"apple"},{"label":"Banana","value":"banana"} ,required: true/false,requireMessage: "Custom message for require"

Usage

import React from "react";
import FormBuilder from "reactjs-form-builder";

export default function Example(props) {

    const [form, setForm] = useState({
        fields: {
            name: {
                label: "Product Name",
                type: "text",
                placeholder: "Custom Placeholder",
                required: true,
                requireMessage: "This Field is Required" // To customize message if field is empty
            },
            description: {
                label: "Product Name",
                type: "textarea",
                required: true,
            },
            categories: {
                label: "Categories",
                type: "select",
                options: [
                    { 'label': "Apple", 'value': 1 },
                    { 'label': "Banana", 'value': 2 }
                ],
                placeholder: "Custom Placeholder",
                required: true,
                requireMessage: "This Field is Required"
            },
            submit: {
                type: "submit",
                label: "Create Product",
                color: 'btn-primary',
            }
        }
    })

    const submitAction = () => {
        // To get FormData
        var formData = form.getFormData();
        
        // To get value of specific field
        var name = form.fields.name.value;
        var description = form.fields.description.value;
        
        // Perform you action here
    };

    return (
        <FormBuilder
            rowDef={{sm: 6}} // optional - to make the form in row. currently only col-sm is supported
            fields={form}
            onChange={(data) => {
                setForm({ ...data })
            }}
            onSubmit={(data) => {
                setForm({ ...data })
                submitAction();
            }}
        />
    );
}

Actions

if you preform action like focusing onto field on component mount or other actions on field reference. add getAction prop in your FormBuilder Component.

return (
  <FormBuilder
    fields={form}
    getActions={(data)=>{setForm({...data})}
  />
);

getAction prop gives callback and return form state with actions. once getAction is initiated you will have actions key in your field.

Eg. to focus in field.

form.fields.yourtextfield.actions.focus();

Custom Submit Button

To use custom submit button instead of the in inbuild submit button. Use

form.submit();

this will trigger validation of form and onSubmit action.

License

MIT © adsazad

2.5.4

2 years ago

2.5.0

2 years ago

2.5.2

2 years ago

2.5.1

2 years ago

2.5.3

2 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.10

4 years ago

1.3.13

4 years ago

1.3.14

4 years ago

1.3.11

4 years ago

1.3.12

4 years ago

1.3.17

4 years ago

1.3.15

4 years ago

1.3.16

4 years ago

1.3.9

4 years ago

1.3.8

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.2.5

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.4

4 years ago

1.2.0

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.1.10

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago