fix: improve id type semantic and restrict possible types to text and number

This commit is contained in:
Jean-Baptiste
2021-08-19 13:54:56 +02:00
committed by Dan Ribbens
parent bc2a6e1575
commit 29529b2c56
10 changed files with 45 additions and 54 deletions

View File

@@ -1,18 +1,19 @@
import { Field } from '../../../../../fields/config/types';
import { text } from '../../../../../fields/validations';
import validations from '../../../../../fields/validations';
const formatFields = (collection, isEditing) => {
let fields = [
...collection.fields,
];
if (collection.id && !isEditing) {
if (collection.idType && !isEditing) {
const defaultValidate = validations[collection.idType];
fields = [
{
name: 'id',
type: 'text',
type: collection.idType,
label: 'ID',
required: true,
validate: (val) => text(val, { required: true }),
validate: (val) => defaultValidate(val, { required: true }),
} as Field,
...fields,
];