Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Mobx React Form | 1,077 | 107 | 26 | 2 days ago | 198 | June 19, 2022 | 45 | mit | TypeScript | |
Reactive MobX Form State Management | ||||||||||
Formstate | 370 | 13 | 26 | 8 months ago | 38 | July 20, 2022 | 8 | mit | TypeScript | |
❤️ Form state so simple that you will fall in love 🌹 | ||||||||||
React Native Starter Kit | 225 | 5 years ago | 5 | JavaScript | ||||||
Mstform | 79 | 5 days ago | 95 | October 05, 2021 | 23 | mit | TypeScript | |||
Mobx State Tree Form-library | ||||||||||
React Forms Mobx | 54 | 7 years ago | 2 | mit | JavaScript | |||||
Example app to be used with the article "Handling React Forms with Mobx Observables": https://blog.risingstack.com/handling-react-forms-with-mobx-observables/ | ||||||||||
Reactive Mobx Form | 47 | 1 | a year ago | 70 | September 29, 2021 | 7 | mit | TypeScript | ||
Reactive forms for applications running on React and MobX | ||||||||||
Smashing Form | 38 | 2 | 2 years ago | 13 | July 01, 2020 | 19 | TypeScript | |||
MobX powered forms in React | ||||||||||
Formstate X | 33 | 2 | 5 months ago | 27 | November 08, 2022 | 8 | mit | TypeScript | ||
Manage state of your form with ease. | ||||||||||
Mobx Form Validate | 30 | 6 | 1 | 6 years ago | 3 | December 17, 2016 | 4 | JavaScript | ||
Mobx React Form Devtools | 30 | 10 | 6 | 16 days ago | 31 | February 26, 2019 | 4 | mit | TypeScript | |
DevTools for MobX React Form |
npm install --save mobx-react-form
See Validation Plugins for more info on supported packages.
Below we are creating a plugins
object using the validatorjs
package to enable DVR
functionalities (Declarative Validation Rules).
import dvr from 'mobx-react-form/lib/validators/DVR';
import validatorjs from 'validatorjs';
const plugins = {
dvr: dvr(validatorjs)
};
Define the fields
as a collection with a rules
property for the validation.
const fields = [{
name: 'email',
label: 'Email',
placeholder: 'Insert Email',
rules: 'required|email|string|between:5,25',
}, {
name: 'password',
label: 'Password',
placeholder: 'Insert Password',
rules: 'required|string|between:5,25',
}, {
name: 'passwordConfirm',
label: 'Password Confirmation',
placeholder: 'Confirm Password',
rules: 'required|string|same:password',
}];
You can also define
fields
as anobject
.
const hooks = {
onSuccess(form) {
alert('Form is valid! Send the request here.');
// get field values
console.log('Form Values!', form.values());
},
onError(form) {
alert('Form has errors!');
// get all form errors
console.log('All form errors', form.errors());
}
}
Simply pass the fields
, plugins
and hooks
objects to the constructor
import MobxReactForm from 'mobx-react-form';
const myForm = new MobxReactForm({ fields }, { plugins, hooks });
The package provide some built-in and ready to use Event Handlers:
onSubmit(e)
, onClear(e)
, onReset(e)
& more...
import React from 'react';
import { observer } from 'mobx-react';
export default observer(({ myForm }) => (
<form onSubmit={myForm.onSubmit}>
<label htmlFor={myForm.$('email').id}>
{myForm.$('email').label}
</label>
<input {...myForm.$('email').bind()} />
<p>{myForm.$('email').error}</p>
{/* ... other inputs ... */}
<button type="submit" onClick={myForm.onSubmit}>Submit</button>
<button type="button" onClick={myForm.onClear}>Clear</button>
<button type="button" onClick={myForm.onReset}>Reset</button>
<p>{myForm.error}</p>
</form>
));
Other Field Props are available. See the docs for more details.
See how to implement the same configuration of this quickstart extending the Form class
yarn test
yarn run build
yarn run commit
When opening new issues, provide the setup of your form in a CodeSandbox.
These issues, and the ones which provides also PR with failing tests will get higher priority.
This project exists thanks to all the people who contribute.
Thank you to all our backers! 🙏 [Become a backer]
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]