Skip to content

Commit

Permalink
Merge pull request #134 from tjinauyeung/fix/empty-object-in-errors-w…
Browse files Browse the repository at this point in the history
…hen-field-is-array
  • Loading branch information
larrybotha authored Aug 29, 2021
2 parents 6519d92 + 11a1e79 commit f8bc548
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 95 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = {
root: true,

ignorePatterns: ['test/**/*.js'],

extends: ['eslint:recommended', 'plugin:unicorn/recommended', 'prettier'],

rules: {
Expand Down
14 changes: 8 additions & 6 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,23 @@ function getErrorsFromSchema(initialValues, schema, errors = {}) {
errors[key] = getErrorsFromSchema(
initialValues[key],
schema[key].fields,
Object.assign({}, errors[key]),
{...errors[key]},
);
break;
}

case schema[key].type === 'array': {
const values =
initialValues && initialValues[key] ? initialValues[key] : [];
errors[key] = values.map((value) =>
getErrorsFromSchema(
errors[key] = values.map((value) => {
const innerError = getErrorsFromSchema(
value,
schema[key].innerType.fields,
Object.assign({}, errors[key]),
),
);
{...errors[key]},
);

return Object.keys(innerError).length > 0 ? innerError : '';
});
break;
}

Expand Down
Loading

0 comments on commit f8bc548

Please sign in to comment.