Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork131
Reactive MobX Form State Management
License
foxhound87/mobx-react-form
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
- ExtensiblesValidation Plugins.
- Sync & Async Validation (w/ Promises & automatic errors).
- Nested Fields (w/ Serialization & Validation).
- Nested Forms (w/ Nested Submission & Validation Hooks).
- Event Hooks,Event Handlers &Validation Hooks
- FunctionalComputed Field Props
- Field PropsObservers & Interceptors
- FieldProps Bindings for custom Components.
- Support for Material UI, React Widgets, React Select & more.
- Forms Composer: to handle multi-forms submit, validations and other actions
- DedicatedDevTools Package.
npm install --save mobx-react-form
Below we are creating aplugins object using thevalidatorjs package to enableDVR functionalities (Declarative Validation Rules).
importdvrfrom'mobx-react-form/lib/validators/DVR';importvalidatorjsfrom'validatorjs';constplugins={dvr:dvr({package:validatorjs})};
SeeValidation Plugins for more info on supported packages.
Define thefields as a collection with arules property for the validation.
constfields=[{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',type:'password',},{name:'passwordConfirm',label:'Password Confirmation',placeholder:'Confirm Password',rules:'required|string|same:password',type:'password',}];
SeeFields Definitions and all availableField Props on the docs.
consthooks={onSuccess(form){alert('Form is valid! Send the request here.');// get field valuesconsole.log('Form Values!',form.values());},onError(form){alert('Form has errors!');// get all form errorsconsole.log('All form errors',form.errors());}}
See more on the docs about theValidation Hooks and theEvent Hooks
Simply pass thefields,plugins andhooks objects to the constructor
importMobxReactFormfrom'mobx-react-form';constmyForm=newMobxReactForm({ fields},{ plugins, hooks});
Learn more on the docs about theForm Instance and theForm Options
The package provide some built-in and ready to use Event Handlers:
onSubmit(e),onClear(e),onReset(e) &more...
importReactfrom'react';import{observer}from'mobx-react';exportdefaultobserver(({ myForm})=>(<formonSubmit={myForm.onSubmit}><labelhtmlFor={myForm.$('email').id}>{myForm.$('email').label}</label><input{...myForm.$('email').bind()}/><p>{myForm.$('email').error}</p>{/* ... other inputs ... */}<buttontype="submit"onClick={myForm.onSubmit}>Submit</button><buttontype="button"onClick={myForm.onClear}>Clear</button><buttontype="button"onClick={myForm.onReset}>Reset</button><p>{myForm.error}</p></form>));
See more on the docs about theField Props Bindings
See how to implement the same configuration of this quickstart extending the Form class
- Fork the repository
- Make applicable changes (with tests!)
- To run tests:
npm run test - Ensure builds succeed:
npm run build - Commit and run pre-commit checks:
npm run commit
When opening new issues, provide the setup of your form in aCodeSandbox.
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]
About
Reactive MobX Form State Management
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
