UNPKG

redux-form

Version:

A higher order component decorator for forms using Redux and React

33 lines (27 loc) 817 B
import plain from './structure/plain'; var toArray = function toArray(value) { return Array.isArray(value) ? value : [value]; }; var getError = function getError(value, values, props, validators, name) { var array = toArray(validators); for (var i = 0; i < array.length; i++) { var error = array[i](value, values, props, name); if (error) { return error; } } }; export default function generateValidator(validators, _ref) { var getIn = _ref.getIn; return function (values, props) { var errors = {}; Object.keys(validators).forEach(function (name) { var value = getIn(values, name); var error = getError(value, values, props, validators[name], name); if (error) { errors = plain.setIn(errors, name, error); } }); return errors; }; }