Save and load radio custom field
[MAILPOET-2453]
This commit is contained in:
committed by
Rostislav Wolný
parent
cb7c7bc1f6
commit
9afba728c6
@@ -2,15 +2,29 @@
|
||||
const mapCustomField = (block, customFields, mappedCommonProperties) => {
|
||||
const customField = customFields.find((cf) => cf.id === block.attributes.customFieldId);
|
||||
if (!customField) return null;
|
||||
return {
|
||||
const typesMap = {
|
||||
'mailpoet-form/custom-text': 'text',
|
||||
'mailpoet-form/custom-textarea': 'textarea',
|
||||
'mailpoet-form/custom-radio': 'radio',
|
||||
};
|
||||
const mapped = {
|
||||
...mappedCommonProperties,
|
||||
id: block.attributes.customFieldId.toString(),
|
||||
name: customField.name,
|
||||
params: {
|
||||
...mappedCommonProperties.params,
|
||||
validate: block.attributes.validate,
|
||||
},
|
||||
type: typesMap[block.name],
|
||||
};
|
||||
if (Object.prototype.hasOwnProperty.call(block.attributes, 'validate')) {
|
||||
mapped.params.validate = block.attributes.validate;
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(block.attributes, 'displayLabel') && block.attributes.displayLabel) {
|
||||
mapped.params.display_label = '1';
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(block.attributes, 'values')) {
|
||||
mapped.params.values = block.attributes.values.map((value) => ({
|
||||
value: value.name,
|
||||
}));
|
||||
}
|
||||
return mapped;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@@ -7,18 +7,23 @@ const mapCustomField = (item, customFields, mappedCommonProperties) => {
|
||||
const namesMap = {
|
||||
text: 'mailpoet-form/custom-text',
|
||||
textarea: 'mailpoet-form/custom-textarea',
|
||||
radio: 'mailpoet-form/custom-radio',
|
||||
};
|
||||
const mapped = {
|
||||
...mappedCommonProperties,
|
||||
name: formatCustomFieldBlockName(namesMap[customField.type], customField),
|
||||
};
|
||||
mapped.attributes.customFieldId = customField.id;
|
||||
if (
|
||||
item.params
|
||||
&& Object.prototype.hasOwnProperty.call(item.params, 'validate')
|
||||
&& !!item.params.validate
|
||||
) {
|
||||
mapped.attributes.validate = item.params.validate;
|
||||
if (item.params) {
|
||||
if (Object.prototype.hasOwnProperty.call(item.params, 'validate') && !!item.params.validate) {
|
||||
mapped.attributes.validate = item.params.validate;
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(item.params, 'display_label')) {
|
||||
mapped.attributes.displayLabel = !!item.params.display_label;
|
||||
}
|
||||
if (Object.prototype.hasOwnProperty.call(item.params, 'values') && Array.isArray(item.params.values)) {
|
||||
mapped.attributes.values = item.params.values.map((value) => ({ name: value.value }));
|
||||
}
|
||||
}
|
||||
return mapped;
|
||||
};
|
||||
|
Reference in New Issue
Block a user