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)) {
|
||||
throw new Error('formBlocks are expected to be an array.');
|
||||
}
|
||||
const customSegmentsBlock = findBlock(formBlocks, 'mailpoet-form/segment-select');
|
||||
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');
|
||||
}
|
||||
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 = {
|
||||
clientId: 'columns-1',
|
||||
name: 'core/columns',
|
||||
@@ -71,11 +81,24 @@ describe('Form validator', () => {
|
||||
segments: [],
|
||||
},
|
||||
};
|
||||
const blocks = [emailBlock, submitBlock];
|
||||
const blocks = [emailBlock, submitBlock, segmentsBlock];
|
||||
const result = validate(formData, blocks);
|
||||
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', () => {
|
||||
const formData = {
|
||||
settings: {
|
||||
|
Reference in New Issue
Block a user