@bigfishtv/cockpit
Version:
22 lines (21 loc) • 784 B
JavaScript
import selectValue from 'lodash/get';
/**
* Returns a new formValue instance, by removing errors in externalErrorList
* where the fields have changed compared with the values of lastFormValue
*
* For use with @bigfishtv/react-forms
*
* @param {ValueRoot} nextFormValue
* @param {ValueRoot} lastFormValue
* @return {ValueRoot}
*/
export default function invalidateExternalErrorList(nextFormValue, lastFormValue) {
var externalErrorList = nextFormValue._externalErrorList.filter(function (error) {
var path = error.field.replace(/^data\./, '');
return selectValue(lastFormValue.value, path) === selectValue(nextFormValue.value, path);
});
return nextFormValue.createRoot({
params: { forceShowErrors: true },
externalErrorList: externalErrorList
});
}