Merge branch 'master' into ctb/improve-stepper

This commit is contained in:
virginieky 2020-01-08 11:31:43 +01:00 committed by GitHub
commit 860c2e0789
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 37 deletions

View File

@ -27,7 +27,9 @@ const RepeatableComponent = ({
const [, drop] = useDrop({ accept: ItemTypes.COMPONENT });
const componentErrorKeys = Object.keys(formErrors)
.filter(errorKey => errorKey.includes(name))
.filter(errorKey => {
return errorKey.split('.')[0] === name;
})
.map(errorKey => {
return errorKey
.split('.')
@ -123,6 +125,7 @@ const RepeatableComponent = ({
onClick={() => {
if (componentValueLength < max) {
const shouldCheckErrors = hasMinError;
addRepeatableComponentToField(
name,
componentUid,

View File

@ -22,7 +22,6 @@ const cleanData = (retrievedData, currentSchema, componentsSchema) => {
try {
cleanedData = JSON.parse(value);
} catch (err) {
console.error(err);
cleanedData = value;
}

View File

@ -95,45 +95,26 @@ const createYupSchema = (model, { components }) => {
);
if (attribute.repeatable === true) {
const { min, max } = attribute;
const { min, max, required } = attribute;
let componentSchema = yup.lazy(value => {
let baseSchema = yup.array().of(componentFieldSchema);
let componentSchema =
attribute.required === true
? yup
.array()
.of(componentFieldSchema)
.defined()
: yup
.array()
.of(componentFieldSchema)
.nullable();
if (min) {
componentSchema = yup.lazy(array => {
if (attribute.required) {
return yup
.array()
.of(componentFieldSchema)
.defined()
.min(min, errorsTrads.min);
if (min) {
if (required) {
baseSchema = baseSchema.min(min, errorsTrads.min);
} else if (required !== true && isEmpty(value)) {
baseSchema = baseSchema.nullable();
} else {
baseSchema = baseSchema.min(min, errorsTrads.min);
}
}
let schema = yup
.array()
.of(componentFieldSchema)
.nullable();
if (max) {
baseSchema = baseSchema.max(max, errorsTrads.max);
}
if (array && !isEmpty(array)) {
schema = schema.min(min, errorsTrads.min);
}
return schema;
});
}
if (max) {
componentSchema = componentSchema.max(max, errorsTrads.max);
}
return baseSchema;
});
acc[current] = componentSchema;