npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-schema-form

v1.0.5

Published

React JSON Schema Form

Downloads

3,057

Readme

react-schema-form

Join the chat at https://gitter.im/networknt/react-schema-form CircleCI

npm package

React forms based on json schema for form generation and validation. This is a port of the angular schema form project using material-ui for the underlying components.

Live demo

demo

While you are trying the demo forms, you can update the schema and form in the json editor to see the instant re-rendered form. This is a way to build form interactively.

Examples

If you don't have babel-cli installed globally, please do it first.

sudo npm install -g babel-cli

Clone the project and run

cd react-schema-form
npm install
cd example
yarn
npm start

Then open localhost:8080 in a browser.

Installation

npm install react-schema-form --save

There is one added on component react-schema-form-rc-select for multiple select and dynamically loading dropdown from server. To install it.

npm install react-schema-form-rc-select --save

Usage

var { SchemaForm } = require('react-schema-form');

<SchemaForm schema={this.state.schema} form={this.state.form} model={this.props.model} onModelChange={this.props.onModelChange} />

// for example:
_onChange: function() {
    this.setState({
        schema: FormStore.getForm('com.networknt.light.example').schema,
        form: FormStore.getForm('com.networknt.light.example').form
    });
}

Examples

There are some simple forms in the demo to show how each fields to be rendered. For more real world exmaples, please check Light Framework Forms

There are still some angular schema form in this folder and migration is in progress.

If you are interested in how these forms are utilized in the framework, please take a look at a react component Form.jsx

Basically, All forms in this folder will be loaded to an Graph Database and UI is rendered by formId and form model will be validated on the browser as well as backend APIs.

Form format

React-schema-form implements the form format as defined by the json-schema-form standard.

The documentation for that format is located at the json-schema-form wiki.

Customization

react-schema-form provides most fields including FieldSet and Array and they might cover most use cases; however, you might have requirement that needs something that is not built in. In this case, you can implement your own field and inject it into the generic mapper for the builder to leverage your component. By passing a mapper as a props to the SchemaForm, you can replace built in component with yours or you can define a brand new type and provide your component to render it.

react-schema-form-rc-select is an example to provide multiple select to the react schema form.

require('rc-select/assets/index.css');
import RcSelect from 'react-schema-form-rc-select/lib/RcSelect';
...

        var mapper = {
            "rc-select": RcSelect
        };

        var schemaForm = '';
        if (this.state.form.length > 0) {
            schemaForm = (
                <SchemaForm schema={this.state.schema} form={this.state.form} model={this.state.model} onModelChange={this.onModelChange} mapper={mapper} />
            );
        }

Error Handler

The error handler is disabled by default but you can enable it by using showErrors prop on SchemaForm.

...
onValidate = () => {
    if (form is valid) {
        ...
    } else {
        this.setState({ showErrors: true });
    }
}

...
    <>
        <SchemaForm
            schema={schemaObject}
            form={formObject}
            model={modelObject}
            onModelChange={this.onModelChange}
            mapper={mapperObject}
            showErrors={this.state.showErrors}
        />
        <Button onClick={this.validate}>Submit</Button>
    </>

Contributing

See our CONTRIBUTING.md for information on how to contribute.

License

MIT Licensed. Copyright (c) Network New Technologies Inc. 2020.