@bigfishtv/cockpit
Version:
30 lines (28 loc) • 657 B
JavaScript
/**
* 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(completeErrorList = [], keyPath = []) {
const str = keyPath.join('.')
return completeErrorList
.map(error => {
if (error.field.indexOf('data.' + str) === 0) {
return {
...error,
...{
field: 'data.' + error.field.substr(str.length + 6),
},
}
}
return false
})
.filter(a => a)
}