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