Respect global custom field values when adding a field to form
[MAILPOET-2463]
This commit is contained in:
committed by
Pavel Dohnal
parent
223d6fca0f
commit
d319781e34
@ -24,7 +24,7 @@ export function getSettings(customField) {
|
||||
},
|
||||
mandatory: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
default: customField.params.required ? !!customField.params.required : false,
|
||||
},
|
||||
customFieldId: {
|
||||
type: 'string',
|
||||
|
@ -16,7 +16,7 @@ export function getSettings(customField) {
|
||||
},
|
||||
mandatory: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
default: customField.params.required ? !!customField.params.required : false,
|
||||
},
|
||||
defaultToday: {
|
||||
type: 'boolean',
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Icon from '../custom_text/icon.jsx';
|
||||
import Edit from './edit.jsx';
|
||||
import { customFieldValuesToBlockValues } from '../../store/form_body_to_blocks.jsx';
|
||||
|
||||
export const name = 'mailpoet-form/custom-radio';
|
||||
|
||||
@ -20,11 +21,12 @@ export function getSettings(customField) {
|
||||
},
|
||||
mandatory: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
default: customField.params.required ? !!customField.params.required : false,
|
||||
},
|
||||
values: {
|
||||
type: 'array',
|
||||
default: [],
|
||||
default: customField.params.values
|
||||
? customFieldValuesToBlockValues(customField.params.values) : [],
|
||||
},
|
||||
customFieldId: {
|
||||
type: 'string',
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Icon from '../custom_text/icon.jsx';
|
||||
import Edit from './edit.jsx';
|
||||
import { customFieldValuesToBlockValues } from '../../store/form_body_to_blocks.jsx';
|
||||
|
||||
export const name = 'mailpoet-form/custom-select';
|
||||
|
||||
@ -20,11 +21,12 @@ export function getSettings(customField) {
|
||||
},
|
||||
mandatory: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
default: customField.params.required ? !!customField.params.required : false,
|
||||
},
|
||||
values: {
|
||||
type: 'array',
|
||||
default: [],
|
||||
default: customField.params.values
|
||||
? customFieldValuesToBlockValues(customField.params.values) : [],
|
||||
},
|
||||
customFieldId: {
|
||||
type: 'string',
|
||||
|
@ -20,11 +20,11 @@ export function getSettings(customField) {
|
||||
},
|
||||
mandatory: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
default: customField.params.required ? !!customField.params.required : false,
|
||||
},
|
||||
validate: {
|
||||
type: 'string',
|
||||
default: '',
|
||||
default: customField.params.validate ? customField.params.validate : '',
|
||||
},
|
||||
customFieldId: {
|
||||
type: 'string',
|
||||
|
@ -20,11 +20,11 @@ export function getSettings(customField) {
|
||||
},
|
||||
mandatory: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
default: customField.params.required ? !!customField.params.required : false,
|
||||
},
|
||||
validate: {
|
||||
type: 'string',
|
||||
default: '',
|
||||
default: customField.params.validate ? customField.params.validate : '',
|
||||
},
|
||||
lines: {
|
||||
type: 'string',
|
||||
|
@ -1,6 +1,17 @@
|
||||
import { has } from 'lodash';
|
||||
import formatCustomFieldBlockName from '../blocks/format_custom_field_block_name.jsx';
|
||||
|
||||
export const customFieldValuesToBlockValues = (values) => values.map((value) => {
|
||||
const mappedValue = {
|
||||
name: value.value,
|
||||
id: `${Math.random().toString()}-${Date.now()}`,
|
||||
};
|
||||
if (has(value, 'is_checked') && value.is_checked) {
|
||||
mappedValue.isChecked = true;
|
||||
}
|
||||
return mappedValue;
|
||||
});
|
||||
|
||||
const mapCustomField = (item, customFields, mappedCommonProperties) => {
|
||||
const customField = customFields.find((cf) => cf.id === parseInt(item.id, 10));
|
||||
if (!customField) return null;
|
||||
@ -38,16 +49,7 @@ const mapCustomField = (item, customFields, mappedCommonProperties) => {
|
||||
mapped.attributes.defaultToday = !!item.params.is_default_today;
|
||||
}
|
||||
if (has(item.params, 'values') && Array.isArray(item.params.values)) {
|
||||
mapped.attributes.values = item.params.values.map((value) => {
|
||||
const mappedValue = {
|
||||
name: value.value,
|
||||
id: `${Math.random().toString()}-${Date.now()}`,
|
||||
};
|
||||
if (has(value, 'is_checked') && value.is_checked) {
|
||||
mappedValue.isChecked = true;
|
||||
}
|
||||
return mappedValue;
|
||||
});
|
||||
mapped.attributes.values = customFieldValuesToBlockValues(item.params.values);
|
||||
}
|
||||
}
|
||||
return mapped;
|
||||
@ -58,7 +60,7 @@ const mapCustomField = (item, customFields, mappedCommonProperties) => {
|
||||
* @param {array} data - from form.body property
|
||||
* @param {array} customFields - list of all custom fields
|
||||
*/
|
||||
export default (data, customFields = []) => {
|
||||
export const formBodyToBlocks = (data, customFields = []) => {
|
||||
if (!Array.isArray(data)) {
|
||||
throw new Error('Mapper expects form body to be an array.');
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import createReducer from './reducer.jsx';
|
||||
import selectors from './selectors.jsx';
|
||||
import controls from './controls.jsx';
|
||||
import validateForm from './form_validator.jsx';
|
||||
import formBodyToBlocks from './form_body_to_blocks.jsx';
|
||||
import { formBodyToBlocks } from './form_body_to_blocks.jsx';
|
||||
|
||||
export default () => {
|
||||
const formData = { ...window.mailpoet_form_data };
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { expect } from 'chai';
|
||||
import formBodyToBlocks from '../../../../assets/js/src/form_editor/store/form_body_to_blocks.jsx';
|
||||
import { formBodyToBlocks } from '../../../../assets/js/src/form_editor/store/form_body_to_blocks.jsx';
|
||||
|
||||
const emailInput = {
|
||||
type: 'text',
|
||||
|
Reference in New Issue
Block a user