From 9a9c926ff6c4a7d2a74e76f2d48c003b1c834959 Mon Sep 17 00:00:00 2001 From: James Lucas Date: Thu, 19 Oct 2023 14:54:30 +1100 Subject: [PATCH] fix: log an error to console if formBuilder methods are called before it has completed initialisation --- src/js/form-builder.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/js/form-builder.js b/src/js/form-builder.js index 14fafea7f..ff124889b 100644 --- a/src/js/form-builder.js +++ b/src/js/form-builder.js @@ -2488,6 +2488,8 @@ function FormBuilder(opts, element, $) { return formBuilder } +const notInitialised = () => { console.error('formBuilder is still initialising') } + const methods = { init: (options, elems) => { const { i18n, ...opts } = jQuery.extend({}, defaultOptions, options, true) @@ -2495,24 +2497,24 @@ const methods = { const i18nOpts = jQuery.extend({}, defaultI18n, i18n, true) methods.instance = { actions: { - getFieldTypes: null, - addField: null, - clearFields: null, - closeAllFieldEdit: null, - getData: null, - removeField: null, - save: null, - setData: null, - setLang: null, - showData: null, - showDialog: null, - toggleAllFieldEdit: null, - toggleFieldEdit: null, - getCurrentFieldId: null, + getFieldTypes: notInitialised, + addField: notInitialised, + clearFields: notInitialised, + closeAllFieldEdit: notInitialised, + getData: notInitialised, + removeField: notInitialised, + save: notInitialised, + setData: notInitialised, + setLang: notInitialised, + showData: notInitialised, + showDialog: notInitialised, + toggleAllFieldEdit: notInitialised, + toggleFieldEdit: notInitialised, + getCurrentFieldId: notInitialised, }, markup, get formData() { - return methods.instance.actions.getData && methods.instance.actions.getData('json') + return methods.instance.actions.getData !== notInitialised && methods.instance.actions.getData('json') }, promise: new Promise(function (resolve, reject) { mi18n