Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
chanjet-nova-form
Advanced tools
Automagically manage React forms state and automatic validation with MobX.
A TypeScript Branch has been created. Feel free to contribute!
https://foxhound87.github.io/mobx-react-form
https://foxhound87.github.io/mobx-react-form/demo.html
https://github.com/foxhound87/mobx-react-form-demo
Automagically manage React forms state and automatic validation with MobX
npm install --save mobx-react-form
See Validation Plugins & Modes and Supported Validation Packages for more info.
Below we are creating a plugins
object using the validatorjs
package to enable DVR
functionalities (Declarative Validation Rules).
import validatorjs from 'validatorjs';
const plugins = { 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: 'same:password',
}];
You can also define
fields
as anobject
.
import MobxReactForm from 'mobx-react-form';
class MyForm extends MobxReactForm {
onSuccess(form) {
alert('Form is valid! Send the request here.');
// get field values
console.log('Form Values!', form.values());
}
onError(form) {
// get all form errors
console.log('All form errors', form.errors());
// invalidate the form with a custom error message
form.invalidate('This is a generic error message!');
}
}
The Validation Handlers can be decoupled from the class as well.
Simply pass the fields
and plugins
objects to the constructor
export default new MyForm({ fields }, { plugins });
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(({ form }) => (
<form onSubmit={form.onSubmit}>
<label htmlFor={form.$('username').id}>
{form.$('username').label}
</label>
<input {...form.$('username').bind()} />
<p>{form.$('username').error}</p>
...
<button type="submit" onClick={form.onSubmit}>Submit</button>
<button type="button" onClick={form.onClear}>Clear</button>
<button type="button" onClick={form.onReset}>Reset</button>
<p>{form.error}</p>
</form>
));
Other Field Props are available. See the docs for more details.
If you want to contribute to the development, do not hesitate to fork the repo and send pull requests.
And don't forget to star the repo, I will ensure more frequent updates! Thanks!
FAQs
Automagically manage React forms state and automatic validation with MobX.
The npm package chanjet-nova-form receives a total of 2 weekly downloads. As such, chanjet-nova-form popularity was classified as not popular.
We found that chanjet-nova-form demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.