https://github.com/parro-it/redux-submitform-onchange
https://github.com/parro-it/redux-submitform-onchange
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/parro-it/redux-submitform-onchange
- Owner: parro-it
- License: mit
- Created: 2016-02-19T16:55:06.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-02T08:32:15.000Z (over 10 years ago)
- Last Synced: 2024-10-20T01:48:57.855Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# redux-submitform-onvalidation
> Automatically submit a [redux-form](https://github.com/erikras/redux-form) every time
> it validate succesfully, but no more than once in a while.
[](http://travis-ci.org/parro-it/redux-submitform-onvalidation)
[](https://npmjs.org/package/redux-submitform-onvalidation)
[](https://npmjs.org/package/redux-submitform-onvalidation)
## Installation
```bash
npm install --save redux-submitform-onvalidation
```
## Usage
Please refer to the [redux-form](http://erikras.github.io/redux-form/#/examples/synchronous-validation?_k=95xd6r).
```javascript
const submitOn = require('redux-submitform-onvalidation');
const validate = values => {
const errors = {};
if (!values.username) {
errors.username = 'Required';
} else if (values.username.length > 15) {
errors.username = 'Must be 15 characters or less';
}
return errors;
};
...
// this is how you normally validate a redux-form
export default reduxForm({
form: 'synchronousValidation',
fields,
validate
})(SynchronousValidationForm);
// instead, to enable submit on validation:
const validateAndSubmit = submitOn(validate);
const form = reduxForm({
form: 'tunnel',
fields,
validate: validateAndSubmit.validate
}, mapStateToProps )(EditTunnel);
validateAndSubmit.formToSubmit(form);
```
## License
The MIT License (MIT)
Copyright (c) 2015 parro-it