Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: form does not load after DomCententLoaded event has been fired #384

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
kevinchappell marked this conversation as resolved.
Show resolved Hide resolved
}

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