Store both embed codes & form ID
This commit is contained in:
parent
037fe88a3d
commit
c3cb5aa468
|
@ -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>
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue