mirror of
https://github.com/strapi/strapi.git
synced 2025-08-09 09:14:49 +00:00
Fix validation blocking valid submission
This commit is contained in:
parent
3c33ea5650
commit
caa4720005
@ -213,18 +213,9 @@ const createYupSchemaAttribute = (type, validations, options) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'json') {
|
if (type === 'json') {
|
||||||
if (validations.required) {
|
|
||||||
schema = yup.mixed(errorsTrads.required).test('required', errorsTrads.required, (value) => {
|
|
||||||
return value === undefined;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
schema = yup
|
schema = yup
|
||||||
.mixed(errorsTrads.json)
|
.mixed(errorsTrads.json)
|
||||||
.test('isJSON', errorsTrads.json, (value) => {
|
.test('isJSON', errorsTrads.json, (value) => {
|
||||||
if (value === undefined) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSON.parse(value);
|
JSON.parse(value);
|
||||||
|
|
||||||
@ -233,8 +224,12 @@ const createYupSchemaAttribute = (type, validations, options) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.nullable();
|
.nullable()
|
||||||
}
|
.test('required', errorsTrads.required, (value) => {
|
||||||
|
if (validations.required && !value.length) return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'email') {
|
if (type === 'email') {
|
||||||
|
@ -146,7 +146,9 @@ const GenericInput = ({
|
|||||||
hint={hint}
|
hint={hint}
|
||||||
required={required}
|
required={required}
|
||||||
onChange={(json) => {
|
onChange={(json) => {
|
||||||
onChange({ target: { name, value: json } });
|
// Default to null when the field is required and there is no input value
|
||||||
|
const value = !attribute.required && !json.length ? 'null' : json;
|
||||||
|
onChange({ target: { name, value } });
|
||||||
}}
|
}}
|
||||||
minHeight={pxToRem(252)}
|
minHeight={pxToRem(252)}
|
||||||
maxHeight={pxToRem(504)}
|
maxHeight={pxToRem(504)}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user