Skip to content

Commit

Permalink
feat(TU-20040): Add isClosed to onReady callback payload
Browse files Browse the repository at this point in the history
Resolves #647
  • Loading branch information
mathio committed Nov 26, 2024
1 parent 235ecfe commit 1300e26
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
12 changes: 8 additions & 4 deletions docs/callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ import { createWidget } from '@typeform/embed'
import '@typeform/embed/build/css/widget.css'

createWidget('<form-id>', {
onReady: ({ formId }) => {
console.log(`Form ${formId} is ready`)
onReady: ({ formId, isClosed }) => {
console.log(
`Form ${formId} is ready. ${isClosed ? 'It is closed for new responses.' : 'It is open to new responses.'}`
)
},
})
```
Expand All @@ -46,8 +48,10 @@ Or in HTML:
<script src="//embed.typeform.com/next/embed.js"></script>
<script>
// this function needs to be available on global scope (window)
function ready({ formId }) {
console.log(`Form ${formId} is ready`)
function ready({ formId, isClosed }) {
console.log(
`Form ${formId} is ready. ${isClosed ? 'It is closed for new responses.' : 'It is open to new responses.'}`
)
}
</script>
```
Expand Down
5 changes: 3 additions & 2 deletions packages/embed/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ You can listen to form events by providing callback methods:
<link rel="stylesheet" href="//embed.typeform.com/next/css/widget.css" />
<script>
const { open } = window.tf.createPopup('<form-id>', {
onReady: ({ formId }) => {
console.log(`Form ${formId} is ready`)
onReady: ({ formId, isClosed }) => {
console.log(`Form ${formId} is ready. ${isClosed ? 'It is closed for new responses.' : 'It is open to new responses.'}`)
},
onStarted: ({ formId, responseId }) => {
console.log(`Form ${formId} started with response ID ${responseId}`)
Expand Down Expand Up @@ -271,6 +271,7 @@ Callback method receive payload object from the form. Each payload contains form

- onReady
- `formId` (string)
- `isClosed` (boolean) indicates [the form is closed for new responses](https://www.typeform.com/help/a/close-your-form-360050913591/)
- onStarted
- `formId` (string)
- `responseId` (string)
Expand Down
6 changes: 5 additions & 1 deletion packages/embed/src/base/actionable-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ interface WithHeight {
height: number
}

interface WithIsClosed {
isClosed: boolean
}

export type ActionableOptions = {
/**
* Callback function that will be executed once the typeform is ready.
*/
onReady?: (event: WithFormId) => void
onReady?: (event: WithFormId & WithIsClosed) => void
/**
* Callback function that will be executed once the typeform "submission start" event is fired.
*/
Expand Down

0 comments on commit 1300e26

Please sign in to comment.