Skip to content
This repository has been archived by the owner on Jan 27, 2022. It is now read-only.

Latest commit

 

History

History
75 lines (61 loc) · 2.48 KB

README.md

File metadata and controls

75 lines (61 loc) · 2.48 KB

jform-react

Generate react forms using JSON schemas



npm

Table of contents

About

This package is a updated TypeScript rewrite of liform-react and can be used as a drop-in upgrade/replacement It uses Ajv to validate JSON schemas given to the form.

Installation

Node.js 14.0.0 or newer is required.

npm install jform-react --save 

Example usage

import React from 'react';
import ReactDOM from 'react-dom';

import { createStore, combineReducers } from 'redux';
import { reducer as formReducer } from 'redux-form';
import { Provider } from 'react-redux';
import Jform from 'jform-react';


const reducer = combineReducers({
  form: formReducer
})

var schema = {
  "title": "Some form",
  "properties": {
    "name": { "type":"string","title":"Model", "default": "Ziummmm"},
    "description": { "type":"string", "title": "Description", "widget": "textarea" }
  },
  "required": ["name"]
};

const store = (window.devToolsExtension ? window.devToolsExtension()(createStore) : createStore)(reducer)

const showResults = values => {
    window.alert(`You submitted:\n\n${JSON.stringify(values, null, 2)}`)
}

const dest = document.getElementById('form-holder')

ReactDOM.render(
    <Provider store={store}>
        <Jform schema={schema} onSubmit={showResults}/>
    </Provider>,
    dest
)