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: {
|
attributes: {
|
||||||
formID: {
|
formID: {
|
||||||
|
type: 'integer',
|
||||||
|
},
|
||||||
|
seamlessEmbedCode: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
},
|
},
|
||||||
embedCode: {
|
iframeEmbedCode: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
embedType: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
source: 'html',
|
|
||||||
selector: 'div',
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -68,11 +72,17 @@ registerBlockType( 'cognito-forms/cognito-embed', {
|
||||||
* @returns {Mixed} JSX Component.
|
* @returns {Mixed} JSX Component.
|
||||||
*/
|
*/
|
||||||
edit: ( props ) => {
|
edit: ( props ) => {
|
||||||
const handleForm = ( code ) => {
|
const handleForm = ( form ) => {
|
||||||
props.setAttributes( { embedCode: code } );
|
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 (
|
||||||
<Placeholder
|
<Placeholder
|
||||||
icon={ CogIcon }
|
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.
|
* @returns {Mixed} JSX Frontend HTML.
|
||||||
*/
|
*/
|
||||||
save: ( props ) => {
|
save: ( props ) => {
|
||||||
|
const embedCode = ( props.attributes.embedType === 'seamless' ) ? props.attributes.seamlessEmbedCode : props.attributes.iframeEmbedCode;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={ props.className }
|
className={ props.className }
|
||||||
dangerouslySetInnerHTML={ { __html: props.attributes.embedCode } }
|
dangerouslySetInnerHTML={ { __html: embedCode } }
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue