From c3cb5aa468548e8e8e3ec6ef9b8d5cff00f56213 Mon Sep 17 00:00:00 2001 From: Michael Thomas Date: Thu, 23 Dec 2021 21:42:10 +0000 Subject: [PATCH] Store both embed codes & form ID --- src/block/block.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/block/block.js b/src/block/block.js index 07f951c..e9a9bda 100644 --- a/src/block/block.js +++ b/src/block/block.js @@ -47,12 +47,16 @@ registerBlockType( 'cognito-forms/cognito-embed', { ], attributes: { formID: { + type: 'integer', + }, + seamlessEmbedCode: { type: 'string', }, - embedCode: { + iframeEmbedCode: { + type: 'string', + }, + embedType: { type: 'string', - source: 'html', - selector: 'div', }, }, @@ -68,11 +72,17 @@ registerBlockType( 'cognito-forms/cognito-embed', { * @returns {Mixed} JSX Component. */ edit: ( props ) => { - const handleForm = ( code ) => { - props.setAttributes( { embedCode: code } ); + const handleForm = ( form ) => { + const formObj = JSON.parse( form ); + props.setAttributes( { + formID: formObj.id, + seamlessEmbedCode: formObj.seamlessEmbedCode, + iframeEmbedCode: formObj.iframeEmbedCode, + embedType: 'seamless', + } ); }; - if ( ! props.attributes.embedCode ) { + if ( ! props.attributes.formID ) { return ( ); + return (
); }, /** @@ -118,10 +128,11 @@ registerBlockType( 'cognito-forms/cognito-embed', { * @returns {Mixed} JSX Frontend HTML. */ save: ( props ) => { + const embedCode = ( props.attributes.embedType === 'seamless' ) ? props.attributes.seamlessEmbedCode : props.attributes.iframeEmbedCode; return (
);