Allow saving form also when list selection with lists is present
[MAILPOET-2828]
This commit is contained in:
committed by
Veljko V
parent
bef9267593
commit
201c1c7656
@@ -7,8 +7,12 @@ export default (formData, formBlocks) => {
|
|||||||
if (!Array.isArray(formBlocks)) {
|
if (!Array.isArray(formBlocks)) {
|
||||||
throw new Error('formBlocks are expected to be an array.');
|
throw new Error('formBlocks are expected to be an array.');
|
||||||
}
|
}
|
||||||
|
const customSegmentsBlock = findBlock(formBlocks, 'mailpoet-form/segment-select');
|
||||||
const errors = [];
|
const errors = [];
|
||||||
if (!formData.settings.segments || formData.settings.segments.length === 0) {
|
if (
|
||||||
|
(!customSegmentsBlock || customSegmentsBlock.attributes.values.length === 0)
|
||||||
|
&& (!formData.settings.segments || formData.settings.segments.length === 0)
|
||||||
|
) {
|
||||||
errors.push('missing-lists');
|
errors.push('missing-lists');
|
||||||
}
|
}
|
||||||
const emailInput = findBlock(formBlocks, 'mailpoet-form/email-input');
|
const emailInput = findBlock(formBlocks, 'mailpoet-form/email-input');
|
||||||
|
@@ -21,6 +21,16 @@ const submitBlock = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const segmentsBlock = {
|
||||||
|
clientId: 'segments',
|
||||||
|
isValid: true,
|
||||||
|
innerBlocks: [],
|
||||||
|
name: 'mailpoet-form/segment-select',
|
||||||
|
attributes: {
|
||||||
|
values: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const columns = {
|
const columns = {
|
||||||
clientId: 'columns-1',
|
clientId: 'columns-1',
|
||||||
name: 'core/columns',
|
name: 'core/columns',
|
||||||
@@ -71,11 +81,24 @@ describe('Form validator', () => {
|
|||||||
segments: [],
|
segments: [],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const blocks = [emailBlock, submitBlock];
|
const blocks = [emailBlock, submitBlock, segmentsBlock];
|
||||||
const result = validate(formData, blocks);
|
const result = validate(formData, blocks);
|
||||||
expect(result).to.contain('missing-lists');
|
expect(result).to.contain('missing-lists');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should not return error for when segments block with lists is present', () => {
|
||||||
|
const filledSegmentsBlock = { ...segmentsBlock };
|
||||||
|
filledSegmentsBlock.attributes.values = [{ id: 1, name: 'cool people' }];
|
||||||
|
const formData = {
|
||||||
|
settings: {
|
||||||
|
segments: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const blocks = [emailBlock, submitBlock, filledSegmentsBlock];
|
||||||
|
const result = validate(formData, blocks);
|
||||||
|
expect(result).to.be.empty;
|
||||||
|
});
|
||||||
|
|
||||||
it('Should return error for missing email', () => {
|
it('Should return error for missing email', () => {
|
||||||
const formData = {
|
const formData = {
|
||||||
settings: {
|
settings: {
|
||||||
|
Reference in New Issue
Block a user