Store both embed codes & form ID

This commit is contained in:
Michael Thomas 2021-12-23 21:42:10 +00:00
parent 037fe88a3d
commit c3cb5aa468
1 changed files with 19 additions and 8 deletions

View File

@ -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 (
<Placeholder
icon={ CogIcon }
@ -103,7 +113,7 @@ registerBlockType( 'cognito-forms/cognito-embed', {
);
}
return ( <div dangerouslySetInnerHTML={ { __html: props.attributes.embedCode } }></div> );
return ( <div dangerouslySetInnerHTML={ { __html: props.attributes.iframeEmbedCode } }></div> );
},
/**
@ -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 (
<div
className={ props.className }
dangerouslySetInnerHTML={ { __html: props.attributes.embedCode } }
dangerouslySetInnerHTML={ { __html: embedCode } }
>
</div>
);