Merge pull request #4771 from strapi/ctm/fix-components

Fix edit component with min value when not required
This commit is contained in:
Alexandre BODIN 2019-12-19 13:32:27 +01:00 committed by GitHub
commit d6a00ccffd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -52,6 +52,7 @@ const RepeatableComponent = ({
const errorsArray = componentErrorKeys.map(key =>
get(formErrors, [key, 'id'], '')
);
const hasMinError =
get(errorsArray, [0], '').includes('min') &&
!collapses.some(obj => obj.isOpen === true);

View File

@ -266,7 +266,7 @@ const EditViewDataManagerProvider = ({
});
redirectToPreviousPage();
} catch (err) {
console.log({ err });
console.error({ err });
const error = get(
err,
['response', 'payload', 'message', '0', 'messages', '0', 'id'],
@ -281,6 +281,7 @@ const EditViewDataManagerProvider = ({
}
} catch (err) {
const errors = getYupInnerErrors(err);
console.error({ err, errors });
dispatch({
type: 'SUBMIT_ERRORS',

View File

@ -109,7 +109,26 @@ const createYupSchema = (model, { components }) => {
.nullable();
if (min) {
componentSchema = componentSchema.min(min, errorsTrads.min);
componentSchema = yup.lazy(array => {
if (attribute.required) {
return yup
.array()
.of(componentFieldSchema)
.defined()
.min(min, errorsTrads.min);
}
let schema = yup
.array()
.of(componentFieldSchema)
.nullable();
if (array && !isEmpty(array)) {
schema = schema.min(min, errorsTrads.min);
}
return schema;
});
}
if (max) {