Skip to content
Open
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"type": "module",
"scripts": {
"build": "vite build && tsc",
"dev": "vite build --watch",
"prepublish": "npm run build"
},
"repository": {
Expand All @@ -34,6 +35,7 @@
"@formio/js": "5.0.0-rc.69",
"@types/node": "^18.17.5",
"@types/vue": "^2.0.0",
"@types/lodash": "^4.14.202",
"@vue/compiler-sfc": "^3.4.15",
"typescript": "^5.3.3",
"typescript-eslint-parser": "^22.0.0",
Expand All @@ -45,6 +47,6 @@
"dist"
],
"dependencies": {
"@ungap/structured-clone": "^1.2.0"
"lodash": "^4.17.21"
}
}
25 changes: 23 additions & 2 deletions src/components/Form.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { defineComponent, ref, onMounted, onBeforeUnmount, watch, CSSProperties, PropType, Prop, toRefs, toRaw } from 'vue';
import { EventEmitter, Form as FormClass, Webform } from '@formio/js';
import structuredClone from '@ungap/structured-clone';
import { cloneDeep as structuredClone } from 'lodash';
import { FormConstructor, FormHandlers, FormProps, FormSource } from '../types';
import useFormioRef from '../composables/useFormioRef';

Expand Down Expand Up @@ -240,7 +240,6 @@ export const Form = defineComponent({
props.formioform,
props.onFormReady,
props.formReady,
props.form,
props.src,
props.options,
props.url,
Expand All @@ -253,6 +252,28 @@ export const Form = defineComponent({
},
);

// Handle form schema updates intelligently
watch(
() => props.form,
(newForm, oldForm) => {
if (instanceIsReady.value && formInstance.value && newForm && oldForm) {
// Update the form schema without recreating the instance
formInstance.value.form = newForm;
// Trigger a rebuild to apply schema changes
formInstance.value.build(formioRef.value);
} else if (
instanceIsReady.value &&
formInstance.value &&
newForm &&
!oldForm
) {
// Initial form load
formInstance.value.form = newForm;
}
},
{ deep: true },
);

watch(
() => [
instanceIsReady.value,
Expand Down
2 changes: 1 addition & 1 deletion src/components/FormBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineComponent, h, onMounted, onBeforeUnmount, ref, watch, PropType, toRaw } from 'vue';
import { FormBuilder as FormioFormBuilder } from '@formio/js';
import { Component } from '@formio/core';
import structuredClone from '@ungap/structured-clone';
import { cloneDeep as structuredClone } from 'lodash';
import { FormBuilderHandlers, FormBuilderProps, FormType } from '../types';
import useFormioRef from '../composables/useFormioRef';

Expand Down