Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
React Hook Form | 35,218 | 127 | 1,337 | 10 hours ago | 951 | September 23, 2022 | 11 | mit | TypeScript | |
📋 React Hooks for form state management and validation (Web + React Native) | ||||||||||
Formik | 32,411 | 2,455 | 1,807 | 4 days ago | 201 | June 02, 2021 | 766 | apache-2.0 | TypeScript | |
Build forms in React, without the tears 😭 | ||||||||||
React Jsonschema Form | 12,715 | 566 | 281 | 20 hours ago | 103 | December 16, 2019 | 287 | apache-2.0 | TypeScript | |
A React component for building Web forms from JSON Schema. | ||||||||||
Redux Form | 12,611 | 11,781 | 1,243 | 2 months ago | 235 | November 17, 2021 | 491 | mit | JavaScript | |
A Higher Order Component using react-redux to keep form state in a Redux store | ||||||||||
Formily | 9,637 | 119 | 4 days ago | 209 | September 20, 2022 | 14 | mit | TypeScript | ||
📱🚀 🧩 Cross Device & High Performance Normal Form/Dynamic(JSON Schema) Form/Form Builder -- Support React/React Native/Vue 2/Vue 3 | ||||||||||
React Final Form | 7,257 | 500 | 384 | 17 days ago | 76 | April 01, 2022 | 390 | mit | JavaScript | |
🏁 High performance subscription-based form state management for React | ||||||||||
X Render | 6,093 | 1 | 31 | 8 hours ago | 310 | September 21, 2022 | 13 | TypeScript | ||
🚴♀️ 阿里 - 很易用的中后台「表单 / 表格 / 图表」解决方案 | ||||||||||
Unform | 4,514 | 33 | 2 months ago | 16 | February 19, 2021 | 73 | mit | TypeScript | ||
Performance-focused API for React forms 🚀 | ||||||||||
Survey Library | 3,619 | 37 | 15 | 5 hours ago | 384 | September 20, 2022 | 501 | mit | TypeScript | |
Free JavaScript form builder library with integration for React, Angular, Vue, jQuery, and Knockout. | ||||||||||
Form | 2,729 | 7 days ago | 29 | mit | TypeScript | |||||
🤖 Powerful and type-safe form state management for the web. TS/JS, React Form, Solid Form, Svelte Form and Vue Form. |
This project has moved. Starting from 1.0.0 onward, develeopment will continue at https://github.com/formsy/formsy-react/
A form input builder and validator for React JS
How to use | API | Examples |
---|
I wrote an article on forms and validation with React JS, Nailing that validation with React JS, the result of that was this extension.
The main concept is that forms, inputs and validation is done very differently across developers and projects. This extension to React JS aims to be that "sweet spot" between flexibility and reusability.
Build any kind of form element components. Not just traditional inputs, but anything you want and get that validation for free
Add validation rules and use them with simple syntax
Use handlers for different states of your form. Ex. "onSubmit", "onError", "onValid" etc.
Pass external errors to the form to invalidate elements
You can dynamically add form elements to your form and they will register/unregister to the form
You can look at examples in this repo or use the formsy-react-components project to use bootstrap with formsy-react, or use formsy-material-ui to use Material-UI with formsy-react.
npm install formsy-react
and use with browserify etc.bower install formsy-react
See examples
folder for examples. Codepen demo.
Complete API reference is available here.
import Formsy from 'formsy-react';
const MyAppForm = React.createClass({
getInitialState() {
return {
canSubmit: false
}
},
enableButton() {
this.setState({
canSubmit: true
});
},
disableButton() {
this.setState({
canSubmit: false
});
},
submit(model) {
someDep.saveEmail(model.email);
},
render() {
return (
<Formsy.Form onValidSubmit={this.submit} onValid={this.enableButton} onInvalid={this.disableButton}>
<MyOwnInput name="email" validations="isEmail" validationError="This is not a valid email" required/>
<button type="submit" disabled={!this.state.canSubmit}>Submit</button>
</Formsy.Form>
);
}
});
This code results in a form with a submit button that will run the submit
method when the submit button is clicked with a valid email. The submit button is disabled as long as the input is empty (required) or the value is not an email (isEmail). On validation error it will show the message: "This is not a valid email".
import Formsy from 'formsy-react';
const MyOwnInput = React.createClass({
// Add the Formsy Mixin
mixins: [Formsy.Mixin],
// setValue() will set the value of the component, which in
// turn will validate it and the rest of the form
changeValue(event) {
this.setValue(event.currentTarget.value);
},
render() {
// Set a specific className based on the validation
// state of this component. showRequired() is true
// when the value is empty and the required prop is
// passed to the input. showError() is true when the
// value typed is invalid
const className = this.showRequired() ? 'required' : this.showError() ? 'error' : null;
// An error message is returned ONLY if the component is invalid
// or the server has returned an error message
const errorMessage = this.getErrorMessage();
return (
<div className={className}>
<input type="text" onChange={this.changeValue} value={this.getValue()}/>
<span>{errorMessage}</span>
</div>
);
}
});
The form element component is what gives the form validation functionality to whatever you want to put inside this wrapper. You do not have to use traditional inputs, it can be anything you want and the value of the form element can also be anything you want. As you can see it is very flexible, you just have a small API to help you identify the state of the component and set its value.
npm install
npm run examples
runs the development server on localhost:8080
npm test
runs the testsCopyright (c) 2014-2016 PatientSky A/S