Skip to content

Beautiful Open-Source Form Builder

Enhance Form Management with Dynamic Configuration Updates

Julien Nahum591d21d88874
diff --git a/client/components/open/forms/OpenCompleteForm.vue b/client/components/open/forms/OpenCompleteForm.vue
index 7f0a27900..ee58f0794 100644
--- a/client/components/open/forms/OpenCompleteForm.vue
+++ b/client/components/open/forms/OpenCompleteForm.vue
@@ -266,6 +266,18 @@ if (props.form) {
})
}
+// Watch for changes to the form prop and update formManager
+watch(() => props.form, (newForm) => {
+ // Only update if the form has changed and formManager is initialized
+ if (formManager && newForm) {
+ // Update form manager with the new config
+ formManager.updateConfig(newForm, {
+ submissionId: submissionId.value,
+ urlParams: import.meta.client ? new URLSearchParams(window.location.search) : null,
+ })
+ }
+})
+
// Share the structure service with the working form store only when in admin edit context
watch(() => formManager?.strategy?.value?.admin?.showAdminControls, (showAdminControls) => {
if (workingFormStore && formManager?.structure && showAdminControls) {
diff --git a/client/lib/forms/composables/useFormManager.js b/client/lib/forms/composables/useFormManager.js
index 800127545..b2ae101f7 100644
--- a/client/lib/forms/composables/useFormManager.js
+++ b/client/lib/forms/composables/useFormManager.js
@@ -54,6 +54,26 @@ export function useFormManager(initialFormConfig, mode = FormMode.LIVE, options
const payment = useFormPayment(config, form)
const submission = useFormSubmission(config, form)
+ /**
+ * Updates the form configuration when the entire form reference changes.
+ * @param {Object} newConfig - The new form configuration
+ * @param {Object} options - Optional initialization options
+ * @returns {Promise<void>}
+ */
+ const updateConfig = async (newConfig, options = {}) => {
+ if (!newConfig) return
+
+ // Update the config reference
+ config.value = newConfig
+
+ // Reset form state
+ state.isSubmitted = false
+ state.currentPage = 0
+
+ // Reinitialize with new config
+ return initialize(options)
+ }
+
/**
* Initializes the form: loads data, resets state, starts timer.
* @param {Object} options - Initialization options (passed to useFormInitialization).
@@ -303,6 +323,7 @@ export function useFormManager(initialFormConfig, mode = FormMode.LIVE, options
// Core Methods
initialize,
+ updateConfig, // New method to update form config
nextPage,
previousPage,
submit,