mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
Fix enumeration field
This commit is contained in:
parent
c1464f73be
commit
be9d94da53
@ -306,7 +306,11 @@ export function updateTempContentType() {
|
||||
// utils
|
||||
export const buildModelAttributes = attributes => {
|
||||
const formattedAttributes = attributes.reduce((acc, current) => {
|
||||
acc[current.name] = current.params;
|
||||
if (current.params.type === 'enumeration') {
|
||||
acc[current.name] = Object.assign(current.params, { enum: current.params.enum.join(',') });
|
||||
} else {
|
||||
acc[current.name] = current.params;
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
@ -331,6 +335,8 @@ export const formatModelAttributes = attributes =>
|
||||
if (curr === 'plugin' && !!value) {
|
||||
acc2.params.pluginValue = value;
|
||||
acc2.params.plugin = true;
|
||||
} else if (curr === 'enum') {
|
||||
acc2.params.enum = value.split(',');
|
||||
} else {
|
||||
acc2.params[curr] = value;
|
||||
}
|
||||
|
||||
@ -41,8 +41,9 @@ class AttributeForm extends React.Component {
|
||||
|
||||
getFormErrors = () => {
|
||||
const { alreadyTakenAttributes, attributeToEditName, modifiedData } = this.props;
|
||||
const currentForm = this.getCurrentForm();
|
||||
|
||||
let formErrors = {};
|
||||
const formValidations = this.getFormValidations();
|
||||
const alreadyTakenAttributesUpdated = alreadyTakenAttributes.filter(
|
||||
attribute => attribute !== attributeToEditName,
|
||||
);
|
||||
@ -55,14 +56,15 @@ class AttributeForm extends React.Component {
|
||||
formErrors = { name: [{ id: `${pluginId}.error.attribute.taken` }] };
|
||||
}
|
||||
|
||||
// TODO NEED TO HANDLE OTHER VALIDATIONS
|
||||
formErrors = Object.keys(modifiedData).reduce((acc, current) => {
|
||||
const { custom, validations } = currentForm.find(input => input.name === current) || {
|
||||
validations: {},
|
||||
};
|
||||
formErrors = Object.keys(formValidations).reduce((acc, current) => {
|
||||
const { custom, validations } = formValidations[current];
|
||||
const value = modifiedData[current];
|
||||
|
||||
if (validations.required === true && value === '' && custom === true) {
|
||||
if (!value && validations.required === true && custom !== true) {
|
||||
acc[current] = [{ id: `${pluginId}.error.validation.required` }];
|
||||
}
|
||||
|
||||
if (custom === true && validations.required === true && value === '') {
|
||||
acc[current] = [{ id: `${pluginId}.error.validation.required` }];
|
||||
}
|
||||
|
||||
@ -77,6 +79,22 @@ class AttributeForm extends React.Component {
|
||||
return formErrors;
|
||||
};
|
||||
|
||||
getFormValidations = () => {
|
||||
const { attributeType } = this.props;
|
||||
const form = supportedAttributes[attributeType];
|
||||
|
||||
return Object.keys(form).reduce((acc, current) => {
|
||||
return {
|
||||
...acc,
|
||||
...form[current].items.reduce((acc2, curr) => {
|
||||
acc2[curr.name] = { validations: curr.validations, custom: curr.custom };
|
||||
|
||||
return acc2;
|
||||
}, {}),
|
||||
};
|
||||
}, {});
|
||||
};
|
||||
|
||||
handleCancel = () => {
|
||||
const { push } = this.props;
|
||||
|
||||
|
||||
@ -219,7 +219,7 @@
|
||||
"label": {
|
||||
"id": "content-type-builder.form.attribute.item.enumeration.rules"
|
||||
},
|
||||
"name": "enumValue",
|
||||
"name": "enum",
|
||||
"type": "textarea",
|
||||
"placeholder": "content-type-builder.form.attribute.item.enumeration.placeholder",
|
||||
"value": false,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user