UNPKG

@bigfishtv/cockpit

Version:

31 lines (28 loc) 1.07 kB
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /** * Utilities for react-forms * @module Utilities/reactFormsUtils */ /** * Returns a subset of errors from a react-forms formValue errorList * and changes the field key to match the new formValue root * * @param {Array} completeErrorList * @param {Array} keyPath * @return {Array} */ export function extractErrorList() { var completeErrorList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var keyPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; var str = keyPath.join('.'); return completeErrorList.map(function (error) { if (error.field.indexOf('data.' + str) === 0) { return _extends({}, error, { field: 'data.' + error.field.substr(str.length + 6) }); } return false; }).filter(function (a) { return a; }); }