react-simple-json-schema-form a simple react component that builds a HTML form from a json object.
npm install --save react-simple-json-schema-form
import React from "react"
import jsonSchema from "./schema.json" // Your custom json schema
import "react-simple-json-schema-form/build/styles.css"
import JsonParadiseSchema from "react-simple-json-schema-form"
function App() {
const send = (params, properties) => {
// params - received values entered by the user after onSubmit
console.log(params)
console.log(properties)
}
return (
<div className="App">
<JsonParadiseSchema schema={ schema } onSubmit={ send }/>
</div>
)
}
export default App
{
"title": "A registration form",
"description": "A simple form example.",
"required": [
"firstName",
"lastName",
"password",
"termsOfUse"
],
"properties": {
"firstName": {
"type": "string",
"title": "First name",
"value": "Chuck",
"autoFocus": true
},
"lastName": {
"type": "string",
"title": "Last name"
},
"age": {
"type": "integer",
"title": "Age",
"description": "(earthian year)"
},
"bio": {
"type": "string",
"title": "Bio",
"isTextarea": true
},
"password": {
"type": "password",
"title": "Password",
"minLength": "3",
"hint": "Hint: Make it strong!"
},
"confirmPassword": {
"type": "confirmPassword",
"title": "Confirm password",
},
"termsOfUse": {
"type": "checkbox",
"value": true,
"title": "You agree terms of use"
}
},
"submitValue": "Send"
}
h1 heading (optional parameter).
h2 heading (optional parameter).
An array containing the names (Object key(s)) of the fields to be filled, otherwise the form will not pass validation.
This is an optional parameter, inside only the string
An object that contains objects (key names are custom) that describe field customization.
Input type may equal - string | integer(number) | mail | password | checkbox | confirmPassword (unique)
.
Title for your field.
The contents of your field, type string
, can be Boolean, if properties.yourCustomName(termsOfUse).type = checkbox
.
Focuses on the field when loading the schema.
Descriptions of your field under the heading.
Creates a large textarea instead of Input
field for more information.
The minimum number of characters to pass validation.
The tooltip that will be under your field.
The name of your button.
Callback after the user clicks the button and the form passes validation.