gateschema-form-react
A React component for generating forms from gateschema-js.
Features
- GateSchema driven
- Auto validation
- Auto updating form data when user inputs value
- Conditional fields
- Able to change schema dynamically
- Extendible, custom form component
How it works
It transforms a gateschema-js instance and the input value into a StateForm state, and use a StateForm implemetation to display the form.
Quick Start
In this example we use stateform-antd as StateForm layer
// file: GateSchemaForm.js // stateform implementation // 1. create StateForm component// see https://github.com/stateform/stateform-antd for more detailsconst StateForm = // 2. create GateSchemaForm componentconst GateSchemaForm =
// file: App.jsx// your schemaconst schema = _ required Component { superprops thisstate = schema value: {} } { console } { const schema value = thisstate return <GateSchemaForm schema=schema value=value /> }
N.B. As user fills the form, GateSchemaForm
will mutate the properties of the passing value
object.
Using with redux
// store.js =
// App.jsx const schema = _ Component { console } { return <Provider store=store> <GateSchemaForm name="myForm" // now the form is binding to store.form.myForm schema=schema onSubmit=handleSubmit > </GateSchemaForm> </Provider> }
Live Expamples on CodeSandbox
Install
npm install gateschema-form-react --save
Usage
Use the other
keyword to pass your StateForm options.
Example
const schema = _ require
Q&A
Custom validation ?
This form component is driven by gateschema. You should define your GateSchema keyword for custom validations
Conditional fields ?
Use switch
keyword
const schema = _
Custom component ?
Extend the StateForm implementation
Changelog
See CHANGELOG
License
MIT