redux-form
Version:
A higher order component decorator for forms using Redux and React
32 lines (26 loc) • 780 B
JavaScript
;
exports.__esModule = true;
exports["default"] = createHasError;
var getErrorKeys = function getErrorKeys(name, type) {
switch (type) {
case 'Field':
return [name, name + "._error"];
case 'FieldArray':
return [name + "._error"];
default:
throw new Error('Unknown field type');
}
};
function createHasError(_ref) {
var getIn = _ref.getIn;
return function (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 getIn(syncErrors, key) || getIn(asyncErrors, key) || getIn(submitErrors, key);
});
};
}