UNPKG

redux-form

Version:

A higher order component decorator for forms using Redux and React

29 lines (24 loc) 786 B
import plainGetIn from './structure/plain/getIn'; var getErrorKeys = function getErrorKeys(name, type) { switch (type) { case 'Field': return [name, name + '._error']; case 'FieldArray': return [name + '._error']; } }; var createHasError = function createHasError(_ref) { var getIn = _ref.getIn; var hasError = function hasError(field, syncErrors, asyncErrors, submitErrors) { if (!syncErrors && !asyncErrors && !submitErrors) { return false; } var name = getIn(field, 'name'); var type = getIn(field, 'type'); return getErrorKeys(name, type).some(function (key) { return plainGetIn(syncErrors, key) || getIn(asyncErrors, key) || getIn(submitErrors, key); }); }; return hasError; }; export default createHasError;