From c77da616f20549dc59aecafd3b091c49355fd08c Mon Sep 17 00:00:00 2001 From: soupette Date: Tue, 3 Dec 2019 13:16:45 +0100 Subject: [PATCH] Fix oneWay, manyWay relation validations --- .../admin/src/containers/FormModal/utils/forms.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/utils/forms.js b/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/utils/forms.js index 06db89261c..a3a9d691e3 100644 --- a/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/utils/forms.js +++ b/packages/strapi-plugin-content-type-builder/admin/src/containers/FormModal/utils/forms.js @@ -206,11 +206,16 @@ const forms = { .matches(NAME_REGEX, errorsTrads.regex) .unique(errorsTrads.unique, alreadyTakenAttributes) .required(errorsTrads.required), - targetAttribute: yup - .string() - .matches(NAME_REGEX, errorsTrads.regex) - .unique(errorsTrads.unique, targetAttributeAlreadyTakenValue) - .required(errorsTrads.required), + targetAttribute: yup.lazy(() => { + let schema = yup.string(); + + if (!['oneWay', 'manyWay'].includes(dataToValidate.nature)) { + schema = schema.matches(NAME_REGEX, errorsTrads.regex); + } + return schema + .unique(errorsTrads.unique, targetAttributeAlreadyTakenValue) + .required(errorsTrads.required); + }), target: yup.string().required(errorsTrads.required), nature: yup.string().required(), dominant: yup.boolean().nullable(),