mirror of
https://github.com/strapi/strapi.git
synced 2025-08-08 08:46:42 +00:00
RepeatableComponent: Simplify error handling and fix all nesting levels
This commit is contained in:
parent
1f811ed9a7
commit
c3383c63b1
@ -1,14 +1,10 @@
|
|||||||
import take from 'lodash/take';
|
export default function getComponentErrorKeys(name, formErrors) {
|
||||||
|
|
||||||
export default function getComponentErrorKeys(name, formErrors, isNested = false) {
|
|
||||||
return Object.keys(formErrors)
|
return Object.keys(formErrors)
|
||||||
.filter((errorKey) => {
|
.filter(errorKey => errorKey.startsWith(name))
|
||||||
return take(errorKey.split('.'), isNested ? 2 : 1).join('.') === name;
|
.map(errorKey =>
|
||||||
})
|
errorKey
|
||||||
.map((errorKey) => {
|
|
||||||
return errorKey
|
|
||||||
.split('.')
|
.split('.')
|
||||||
.slice(0, name.split('.').length + 1)
|
.slice(0, name.split('.').length + 1)
|
||||||
.join('.');
|
.join('.')
|
||||||
});
|
);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ describe('getComponentErrorKeys', () => {
|
|||||||
'parent.child.1.field': 'validation-error',
|
'parent.child.1.field': 'validation-error',
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(getComponentErrorKeys('parent.child', FIXTURE, true)).toStrictEqual([
|
expect(getComponentErrorKeys('parent.child', FIXTURE)).toStrictEqual([
|
||||||
'parent.child.0',
|
'parent.child.0',
|
||||||
'parent.child.1',
|
'parent.child.1',
|
||||||
]);
|
]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user