redux-form-validations
Advanced tools
@@ -27,5 +27,9 @@ 'use strict'; | ||
| errors = _ref.errors, | ||
| rule = _ref.rule; | ||
| rule = _ref.rule, | ||
| values = _ref.values; | ||
| if ((0, _lodash.get)(rule, 'errorMessage') && !errors[fieldName]) { | ||
| if (typeof rule.errorMessage === 'function') { | ||
| return rule.errorMessage(values, values[fieldName]); | ||
| } | ||
| return rule.errorMessage; | ||
@@ -72,3 +76,3 @@ } | ||
| } else if (!valid) { | ||
| errors[field] = errorMessageFor({ schema: schema, fieldName: field, errors: errors, rule: rule }); | ||
| errors[field] = errorMessageFor({ schema: schema, fieldName: field, errors: errors, rule: rule, values: values }); | ||
| } | ||
@@ -85,3 +89,3 @@ } else { | ||
| } else if (!valid) { | ||
| errors[field] = errorMessageFor({ schema: schema, fieldName: field, errors: errors, rule: rule }); | ||
| errors[field] = errorMessageFor({ schema: schema, fieldName: field, errors: errors, rule: rule, values: values }); | ||
| } | ||
@@ -88,0 +92,0 @@ }); |
+3
-0
| ### v NEXT | ||
| ### v 0.0.8 | ||
| Add dynamic error messages by [Justin Schulz](https://github.com/PepperTeasdale) in [#11](https://github.com/policygenius/redux-form-validations/pull/11) | ||
| ### v 0.0.7 | ||
@@ -4,0 +7,0 @@ - Fix exporting `.isDateBefore()` validator by [Trevor Nelson](https://github.com/trevornelson) in [#8](https://github.com/policygenius/redux-form-validations/pull/8) |
+1
-1
| { | ||
| "name": "redux-form-validations", | ||
| "version": "0.0.7", | ||
| "version": "0.0.8", | ||
| "description": "Validation utilities for redux-form v6", | ||
@@ -5,0 +5,0 @@ "author": "PolicyGenius", |
+9
-0
@@ -64,2 +64,11 @@ # redux-form-validations | ||
| ## Custom validators | ||
| Every field defined in your schema object has top-level keys `warn` and `validate` which are used to build warn and validate functions for redux-form connected components. These keys take a _validator object_, which has the shape: | ||
| `validator`: Function (allFields, value) => Boolean | ||
| If the return value is true, then the field is valid, if false, an error is added. | ||
| `errorMessage`: String || Function (allField, value) => String | ||
| The error message that is returned with the `validate` or `warn` function call when the `validator` returns false. | ||
| ## Prior work | ||
@@ -66,0 +75,0 @@ [redux-form-schema](https://github.com/Lighthouse-io/redux-form-schema) is the main |
178936
0.51%240
1.69%88
11.39%