Skip to content

Events โ€‹

PageBuilderJS emits various DOM events (via CustomEvent) when important user actions occur inside the editor. This allows you to hook into the builder's internal actions and trigger external logic in your application.

๐Ÿ“ก Available Events โ€‹

Event nameDescriptionPayload (event.detail)
onModalSaveFired when a module instance is saved from the edit modalInstanceModule
onUpdateFired when the content structure changesInstanceModule[]
onTemplateCreateA new template is savedTemplate
onTemplateDeleteA template was deletedtemplate name: string
onTemplatesUpdateThe list of templates has changedTemplate[]
onTemplateAppendA template was appended into the canvastemplate name: string

๐Ÿงช Example Usage โ€‹

Using JavaScript: โ€‹

html
<script>
  const builder = document.createElement('block-builder')
  const content = [/* ... */]
  const modules = [/* ... */]
  const toolbar = {/* ... */}

  // Assign data
  builder.modules = modules
  builder.toolbar = toolbar
  builder.content = content

  // Listen to any changes in content structure
  builder.addEventListener('onUpdate', (event) => {
    console.log('Blocks content changed:', event.detail)
  })

  document.body.appendChild(builder)
</script>