Installation

Install

npm install mui-forms

Peer Dependencies

"peerDependencies": {
  "react": "^18.0.0"
}

Basic Usage

  1. Define your schema:
{
    "fields": [
        {
            "name": "first_name",
            "meta": {
                "displayType": "text",
                "displayName": "First Name"
            }
        },
        {
            "name": "last_name",
            "meta": {
                "displayType": "text",
                "displayName": "Last Name"
            }
        }
    ]
}
  1. Import and use MuiForms:
import MuiForms from "mui-forms";
import schema from "<schema_location.json>";
 
<MuiForms
    name="myForm"
    schema={schema}
    onChange={(...data) => {
        // handle data on change
    }}
    onError={(...fieldData) => {
        // handle error
    }}
    onNext={(formData) => {
        // handle next
    }}
    onSubmit={(formData) => {
        // handle form submission
    }}
/>;

Basic Properties

NameDescriptionType
namethe name of the formOptional
configConfiguration options for the formOptional
schemajson based schema to render the formMandatory
controlscustom fieldsOptional
componentscustom interactive fieldsOptional
onChangehandle to be called on field value changeOptional
onErrorhandle to be called on field errorOptional
onNexthandle to be called when user tries to move to next form section (grouped forms)Optional
onPrevioushandle to be called when user tries to move to previous form section (grouped forms)Optional
onSubmithandle to be called on form submissionMandatory
changeResponseModeValue: "form-data", "section-data", "default".
form-data: onChange event will pass all the form data as a second parameter.
section-data: onChange event will pass all the section data as a second parameter.
Optional
nextResponseModeValue: "form-data", "page-data"
form-data: onNext event will send all the form data (onNext).
page-data: onNext event will send all the date of the current page.
Note: onNext is triggered on click of Next button
Optional

Config properties

NameValuesDefault ValueDescriptionType
variantoutlined, standard, filledoutlinedSpecified the field outlook.Optional
sizesmall, medium, largemediumSpecified the field sizes.Optional
gapXAny numberNAAdds horizontal spacing between fields.
All units are in rem.
Optional
gapYAny numberNAAdds vertical spacing between fields.
All units are in rem.
Optional

Star us at github

© Copyright 2023 MuiForms.