redux-form-validations
Advanced tools
Comparing version
@@ -61,33 +61,39 @@ 'use strict'; | ||
buildValidators = function buildValidators(a, b) { | ||
return function (c) { | ||
var d = {}, | ||
e = (0, _keys2.default)((0, _pickBy2.default)(a, function (f) { | ||
return (0, _get2.default)(f, b); | ||
return function (c, d) { | ||
var e = {}, | ||
f = (0, _keys2.default)((0, _pickBy2.default)(a, function (g) { | ||
return (0, _get2.default)(g, b); | ||
})); | ||
(0, _forEach2.default)(e, function (f) { | ||
if (!(0, _isArray2.default)(a[f][b])) { | ||
var g = a[f][b], | ||
h = isRequiredAndNotPresent({ values: c, field: f, rule: g }), | ||
i = isValid({ values: c, field: f, rule: g }); | ||
(0, _forEach2.default)(f, function (g) { | ||
var h = a[g][b]; | ||
if (typeof h === 'function') { | ||
h = h(d); | ||
} | ||
if (h) { | ||
d[f] = 'Required'; | ||
} else if (!i) { | ||
d[f] = errorMessageFor({ schema: a, fieldName: f, errors: d, rule: g, values: c }); | ||
if (!(0, _isArray2.default)(h)) { | ||
var i = h, | ||
j = isRequiredAndNotPresent({ values: c, field: g, rule: i }), | ||
k = isValid({ values: c, field: g, rule: i }); | ||
if (j) { | ||
e[g] = 'Required'; | ||
} else if (!k) { | ||
e[g] = errorMessageFor({ schema: a, fieldName: g, errors: e, rule: i, values: c }); | ||
} | ||
} else { | ||
var j = a[f][b]; | ||
var l = h; | ||
(0, _forEach2.default)(j, function (k) { | ||
var l = isRequiredAndNotPresent({ values: c, field: f, rule: k }), | ||
m = isValid({ values: c, field: f, rule: k }); | ||
(0, _forEach2.default)(l, function (m) { | ||
var n = isRequiredAndNotPresent({ values: c, field: g, rule: m }), | ||
o = isValid({ values: c, field: g, rule: m }); | ||
if (l) { | ||
d[f] = 'Required'; | ||
} else if (!m) { | ||
d[f] = errorMessageFor({ schema: a, fieldName: f, errors: d, rule: k, values: c }); | ||
if (n) { | ||
e[g] = 'Required'; | ||
} else if (!o) { | ||
e[g] = errorMessageFor({ schema: a, fieldName: g, errors: e, rule: m, values: c }); | ||
} | ||
@@ -99,9 +105,9 @@ }); | ||
if (a._fieldArrays) { | ||
(0, _forEach2.default)(a._fieldArrays, function (f, g) { | ||
(0, _forEach2.default)(a._fieldArrays, function (g, h) { | ||
/* eslint-disable no-use-before-define */ | ||
var h = validateNested({ validations: f, type: b, nestedItems: c[g] }); | ||
var i = validateNested({ validations: g, type: b, nestedItems: c[h] }); | ||
/* eslint-disable */ | ||
if (h.length) { | ||
d[g] = h; | ||
if (i.length) { | ||
e[h] = i; | ||
} | ||
@@ -111,3 +117,3 @@ }); | ||
return d; | ||
return e; | ||
}; | ||
@@ -114,0 +120,0 @@ }, |
### v NEXT | ||
### v 0.1.0 | ||
Add ability to construct field validate property as a function that receives props [John Colella](https://github.com/jmcolella) in [#17](https://github.com/policygenius/redux-form-validations/pull/17) | ||
### v 0.0.11 | ||
@@ -4,0 +7,0 @@ Simplify email validation regex [James Lowenthal](https://github.com/JamesAnthonyLow) in [#16](https://github.com/policygenius/redux-form-validations/pull/16) |
{ | ||
"name": "redux-form-validations", | ||
"version": "0.0.11", | ||
"version": "0.1.0", | ||
"description": "Validation utilities for redux-form v6", | ||
@@ -5,0 +5,0 @@ "author": "PolicyGenius", |
@@ -73,2 +73,18 @@ # redux-form-validations | ||
Alternatively, you can assign a function that returns a _validator object_ to either `warn` or `validate` that will receive `props` from your ReduxForm wrapped component. This is helpful if you need to validate based on information outside of the form state. | ||
Example: | ||
```javascript | ||
const { warn, validate } = buildValidations({ | ||
firstName: { | ||
validate: (props) => ({ | ||
validator: (fields) => { | ||
return props.someBoolean && fields.numbers > 0, | ||
} | ||
}), | ||
}, | ||
}); | ||
``` | ||
## Prior work | ||
@@ -75,0 +91,0 @@ [redux-form-schema](https://github.com/Lighthouse-io/redux-form-schema) is the main |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
182297
0.27%290
1.4%104
18.18%20
-4.76%1
Infinity%