Comments (2)
I think this was due to an environment issue (embedding it in Nextjs). I solved it with the following (for anyone who may stumble upon this), took inspiration from here: https://github.com/rottitime/react-hook-window-message-event:
export default function FormBlock({attributes}: Props): JSX.Element {
const {data}: {data?: string} = attributes
let formData: FormData = {}
if (data !== undefined) {
formData = JSON.parse(data)
}
const [height, setHeight] = useState(500)
const [width, setWidth] = useState('100%')
const onWatchEventHandler = useCallback(
({origin, data}) => {
const {message, height, index, width} = data
if (
origin === process.env.NEXT_PUBLIC_GRAVITY_FORMS_URL &&
message === 'size' &&
index === formData?.gravity_form_id
) {
setHeight(height)
setWidth(width)
}
},
[formData?.gravity_form_id],
)
useEffect(() => {
window.addEventListener('message', onWatchEventHandler)
return () => window.removeEventListener('message', onWatchEventHandler)
})
return (
<>
<div className="max-w-4xl mx-auto">
{formData?.gravity_form_id && (
<iframe
id="gfiframe"
src={`${process.env.NEXT_PUBLIC_GRAVITY_FORMS_URL}/gfembed/?f=${formData?.gravity_form_id}`}
width={width}
height={height}
frameBorder="0"
className="gfiframe"
scrolling="no"
onLoad={e => {
const iframe = e.target as HTMLIFrameElement
iframe.contentWindow.postMessage(
{
message: 'size',
index: formData?.gravity_form_id,
},
'*',
)
}}
></iframe>
)}
</div>
</>
)
}
from gravity-forms-iframe.
Thanks for the update and letting us know how you solved this @ttstauss!
from gravity-forms-iframe.
Related Issues (20)
- iframe resize not working. HOT 2
- Getting URL of iframe page HOT 2
- Uncaught TypeError: t.data.split is not a function HOT 1
- Gravity Forms filters (e.g., gform_pre_render, gform_pre_validation, etc.) not working HOT 2
- Style of form embedded HOT 1
- Issue with embedding Gravity form on Clickfunnels page - Can you help please? HOT 1
- Conditional logic & Signature Filed Not working HOT 1
- Iframe works on desktop but not mobile HOT 6
- Thankyou so much HOT 1
- 'X-Frame-Options' to 'sameorigin' Issue HOT 2
- Iframe doesn't show updated form/new changes HOT 1
- iFrame requires login on external site
- Footer issue HOT 1
- enable automatically
- Is this no longer working? iFrames appear empty on any external sites
- Gravity new update, don't work with iframe plugin HOT 6
- No longer works HOT 1
- gform_theme_config is not defined
- Not sending form
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gravity-forms-iframe.