mirror of
https://github.com/strapi/strapi.git
synced 2025-08-08 08:46:42 +00:00
Fix validation blocking valid submission
This commit is contained in:
parent
3c33ea5650
commit
caa4720005
@ -213,28 +213,23 @@ const createYupSchemaAttribute = (type, validations, options) => {
|
||||
}
|
||||
|
||||
if (type === 'json') {
|
||||
if (validations.required) {
|
||||
schema = yup.mixed(errorsTrads.required).test('required', errorsTrads.required, (value) => {
|
||||
return value === undefined;
|
||||
schema = yup
|
||||
.mixed(errorsTrads.json)
|
||||
.test('isJSON', errorsTrads.json, (value) => {
|
||||
try {
|
||||
JSON.parse(value);
|
||||
|
||||
return true;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.nullable()
|
||||
.test('required', errorsTrads.required, (value) => {
|
||||
if (validations.required && !value.length) return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
schema = yup
|
||||
.mixed(errorsTrads.json)
|
||||
.test('isJSON', errorsTrads.json, (value) => {
|
||||
if (value === undefined) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
JSON.parse(value);
|
||||
|
||||
return true;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.nullable();
|
||||
}
|
||||
}
|
||||
|
||||
if (type === 'email') {
|
||||
|
@ -146,7 +146,9 @@ const GenericInput = ({
|
||||
hint={hint}
|
||||
required={required}
|
||||
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)}
|
||||
maxHeight={pxToRem(504)}
|
||||
|
Loading…
x
Reference in New Issue
Block a user