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