diff --git a/assets/js/src/form_editor/store/form_body_to_blocks.jsx b/assets/js/src/form_editor/store/form_body_to_blocks.jsx index 4c0297d10e..9a0802c3f8 100644 --- a/assets/js/src/form_editor/store/form_body_to_blocks.jsx +++ b/assets/js/src/form_editor/store/form_body_to_blocks.jsx @@ -78,8 +78,8 @@ export default (data, customFields = []) => { if (item.params && has(item.params, 'label_within')) { mapped.attributes.labelWithinInput = !!item.params.label_within; } - if (item.params && has(item.params, 'label')) { - mapped.attributes.label = item.params.label; + if (item.params) { + mapped.attributes.label = item.params.label ? item.params.label : null; } switch (item.id) { case 'email': @@ -121,11 +121,13 @@ export default (data, customFields = []) => { name: 'mailpoet-form/submit-button', }; case 'divider': + delete mapped.attributes.label; return { ...mapped, name: 'mailpoet-form/divider', }; case 'html': + delete mapped.attributes.label; return { ...mapped, name: 'mailpoet-form/html', diff --git a/tests/javascript/form_editor/store/form_body_to_blocks.spec.js b/tests/javascript/form_editor/store/form_body_to_blocks.spec.js index 33516000ee..923909a85d 100644 --- a/tests/javascript/form_editor/store/form_body_to_blocks.spec.js +++ b/tests/javascript/form_editor/store/form_body_to_blocks.spec.js @@ -219,6 +219,14 @@ describe('Form Body To Blocks', () => { expect(block.attributes.labelWithinInput).to.be.equal(true); }); + it('Should add a label if label is missing in data', () => { + const input = { ...emailInput, position: '1' }; + delete input.params.label; + const [block] = formBodyToBlocks([{ ...emailInput, position: '1' }]); + checkBlockBasics(block); + expect(block.attributes.label).to.be.equal(null); + }); + it('Should map first name input to block', () => { const [block] = formBodyToBlocks([{ ...firstNameInput, position: '1' }]); checkBlockBasics(block);