-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #158 from jedwards1211/meatier-form
create meatierForm to cut down on boilerplate
- Loading branch information
Showing
4 changed files
with
28 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {reduxForm} from 'redux-form'; | ||
import Joi from 'joi'; | ||
import {parsedJoiErrors} from 'universal/utils/schema'; | ||
import {getFormState} from 'universal/redux/helpers'; | ||
|
||
/** | ||
* A small wrapper for reduxForm that can (optionally) inject a validate method based on the Joi `schema` prop in the | ||
* options, and also injects the necessary `getFormState` for `redux-optimistic-ui`. | ||
*/ | ||
export default function meatierForm(options) { | ||
const {schema} = options | ||
return reduxForm(Object.assign( | ||
options, | ||
{getFormState}, | ||
schema && { | ||
validate(values) { | ||
const results = Joi.validate(values, options.schema, {abortEarly: false}); | ||
return parsedJoiErrors(results.error); | ||
} | ||
} | ||
)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters