mirror of
https://github.com/strapi/strapi.git
synced 2025-08-07 08:16:35 +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, isNested = false) {
|
||||
export default function getComponentErrorKeys(name, formErrors) {
|
||||
return Object.keys(formErrors)
|
||||
.filter((errorKey) => {
|
||||
return take(errorKey.split('.'), isNested ? 2 : 1).join('.') === name;
|
||||
})
|
||||
.map((errorKey) => {
|
||||
return errorKey
|
||||
.filter(errorKey => errorKey.startsWith(name))
|
||||
.map(errorKey =>
|
||||
errorKey
|
||||
.split('.')
|
||||
.slice(0, name.split('.').length + 1)
|
||||
.join('.');
|
||||
});
|
||||
.join('.')
|
||||
);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ describe('getComponentErrorKeys', () => {
|
||||
'parent.child.1.field': 'validation-error',
|
||||
};
|
||||
|
||||
expect(getComponentErrorKeys('parent.child', FIXTURE, true)).toStrictEqual([
|
||||
expect(getComponentErrorKeys('parent.child', FIXTURE)).toStrictEqual([
|
||||
'parent.child.0',
|
||||
'parent.child.1',
|
||||
]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user