Skip to content

Commit

Permalink
fix: formData loading
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchappell committed Aug 30, 2020
1 parent 0534285 commit 86bfa3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/js/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ export class Components extends Data {
setAddress(address, value) {
const [type, id, ...path] = Array.isArray(address) ? address : address.split('.')
const componentType = type.replace(/s?$/, 's')
this[componentType].get(id).set(path, value)
const component = this[componentType].get(id)
if (component) {
component.set(path, value)
}
return component
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class FormeoEditor {
* @param {String|Object} userFormData loaded formData
* @return {Object} formeo references and actions
*/
constructor(options, userFormData) {
constructor({ formData, ...options }, userFormData) {
const _this = this
const mergedOptions = merge(defaults.editor, options)

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

this.userFormData = userFormData
this.userFormData = userFormData || formData

this.Components = Components
Events.init({ debug, ...events })
Expand All @@ -52,8 +52,8 @@ export class FormeoEditor {
get formData() {
return this.Components.formData
}
set formData(data) {
return this.load(data, this.opts)
set formData(data = {}) {
return this.load({ ...this.userFormData, ...data }, this.opts)
}
get json() {
return this.Components.json
Expand Down Expand Up @@ -110,7 +110,7 @@ export class FormeoEditor {
_this.render()
}

load(formData, opts = this.opts) {
load(formData = this.userFormData, opts = this.opts) {
return this.Components.load(formData, opts)
}

Expand Down

0 comments on commit 86bfa3e

Please sign in to comment.