Skip to content

Commit

Permalink
fix: form does not load after DomCententLoaded event has been fired
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchappell committed Nov 27, 2024
1 parent f8b6414 commit 33d0fc4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/lib/js/common/utils/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,6 @@ export function parseData(data = Object.create(null)) {

return data
}


export const cleanFormData = formData => (formData ? clone(parseData(formData)) : {})
10 changes: 7 additions & 3 deletions src/lib/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Controls from './components/controls/index.js'
import Components from './components/index.js'
import { loadPolyfills, fetchIcons, fetchFormeoStyle } from './common/loaders.js'
import { SESSION_LOCALE_KEY } from './constants.js'
import { merge } from './common/utils/index.mjs'
import { cleanFormData, merge } from './common/utils/index.mjs'
import { defaults } from './config.js'

/**
Expand All @@ -32,7 +32,7 @@ export class FormeoEditor {
dom.setOptions = opts
Components.config = config

this.userFormData = userFormData || formData
this.userFormData = cleanFormData(userFormData || formData)

this.Components = Components
this.dom = dom
Expand All @@ -41,7 +41,11 @@ export class FormeoEditor {
this.tooltip = new SmartTooltip()

// Load remote resources such as css and svg sprite
document.addEventListener('DOMContentLoaded', this.loadResources.bind(this))
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', this.loadResources.bind(this))
} else {
this.loadResources()
}
}

get formData() {
Expand Down
3 changes: 1 addition & 2 deletions src/lib/js/renderer.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import isEqual from 'lodash/isEqual'
import dom from './common/dom'
import { uuid, isAddress, isExternalAddress, merge, parseData, clone } from './common/utils/index.mjs'
import { uuid, isAddress, isExternalAddress, merge, cleanFormData } from './common/utils/index.mjs'
import { STAGE_CLASSNAME, UUID_REGEXP } from './constants'
import { fetchDependencies } from './common/loaders'

const RENDER_PREFIX = 'f-'

const cleanFormData = formData => (formData ? clone(parseData(formData)) : {})
const containerLookup = container => (typeof container === 'string' ? document.querySelector(container) : container)
const processOptions = ({ editorContainer, renderContainer, formData, ...opts }) => {
const processedOptions = {
Expand Down

0 comments on commit 33d0fc4

Please sign in to comment.