mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 10:55:37 +00:00
parent
873f810099
commit
8ddf955af2
@ -503,6 +503,8 @@ const forms = {
|
||||
];
|
||||
|
||||
items = uidItems;
|
||||
} else if (type === 'json') {
|
||||
items.splice(0, 1);
|
||||
}
|
||||
|
||||
if (!ATTRIBUTES_THAT_DONT_HAVE_MIN_MAX_SETTINGS.includes(type)) {
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const yup = require('yup');
|
||||
const _ = require('lodash');
|
||||
|
||||
const validators = {
|
||||
required: yup.boolean(),
|
||||
@ -80,11 +81,34 @@ const isValidRegExpPattern = {
|
||||
test: val => val === '' || new RegExp(val),
|
||||
};
|
||||
|
||||
const isValidDefaultJSON = {
|
||||
name: 'isValidDefaultJSON',
|
||||
message: '${path} is not a valid JSON',
|
||||
test: val => {
|
||||
if (val === undefined) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_.isNumber(val) || _.isNull(val) || _.isObject(val) || _.isArray(val)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
JSON.parse(val);
|
||||
|
||||
return true;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validators,
|
||||
areEnumValuesUnique,
|
||||
isValidCollectionName,
|
||||
isValidCategoryName,
|
||||
isValidDefaultJSON,
|
||||
isValidName,
|
||||
isValidIcon,
|
||||
isValidKey,
|
||||
|
||||
@ -6,6 +6,7 @@ const yup = require('yup');
|
||||
const {
|
||||
validators,
|
||||
areEnumValuesUnique,
|
||||
isValidDefaultJSON,
|
||||
isValidName,
|
||||
isValidEnum,
|
||||
isValidUID,
|
||||
@ -112,6 +113,7 @@ const getTypeShape = (attribute, { modelType, attributes } = {}) => {
|
||||
}
|
||||
case 'json': {
|
||||
return {
|
||||
default: yup.mixed().test(isValidDefaultJSON),
|
||||
required: validators.required,
|
||||
unique: validators.unique,
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user