Beautiful Open-Source Form Builder
Enhance Form Manager with Reactive Mode Handling
Julien Nahum360b1160629d
diff --git a/client/components/open/forms/OpenCompleteForm.vue b/client/components/open/forms/OpenCompleteForm.vueindex ee58f0794..511166274 100644--- a/client/components/open/forms/OpenCompleteForm.vue+++ b/client/components/open/forms/OpenCompleteForm.vue@@ -246,6 +246,8 @@ const isAutoSubmit = ref(import.meta.client && window.location.href.includes('au// Create a reactive reference directly from the propconst darkModeRef = toRef(props, 'darkMode')+// Create a reactive reference for the mode prop+const modeRef = toRef(props, 'mode')// Add back the local theme computationconst theme = computed(() => {@@ -258,7 +260,8 @@ const theme = computed(() => {let formManager = nullif (props.form) {formManager = useFormManager(props.form, props.mode, {- darkMode: darkModeRef+ darkMode: darkModeRef,+ mode: modeRef})formManager.initialize({submissionId: submissionId.value,diff --git a/client/lib/forms/composables/useFormManager.js b/client/lib/forms/composables/useFormManager.jsindex b2ae101f7..21200c2de 100644--- a/client/lib/forms/composables/useFormManager.js+++ b/client/lib/forms/composables/useFormManager.js@@ -19,11 +19,17 @@ import { cloneDeep } from 'lodash'* Initializes and coordinates various form composables (Structure, Init, Validation, etc.)* based on the provided form configuration and mode.*/-export function useFormManager(initialFormConfig, mode = FormMode.LIVE, options = {}) {+export function useFormManager(initialFormConfig, initialMode = FormMode.LIVE, options = {}) {// --- Reactive State ---const config = ref(initialFormConfig) // Use ref for potentially replaceable configconst form = useForm() // Core vForm instance- const strategy = computed(() => createFormModeStrategy(mode)) // Strategy based on mode++ // Make mode reactive - accept either a ref or a static value+ const mode = options.mode && typeof options.mode === 'object' && 'value' in options.mode+ ? options.mode+ : ref(initialMode)++ const strategy = computed(() => createFormModeStrategy(mode.value)) // Strategy based on reactive mode// Use the passed darkMode ref if it's a ref, otherwise create a new refconst darkMode = options.darkMode && typeof options.darkMode === 'object' && 'value' in options.darkMode@@ -117,7 +123,7 @@ export function useFormManager(initialFormConfig, mode = FormMode.LIVE, optionsconst paymentBlock = structure.currentPagePaymentBlock.valueif (paymentBlock) {// In editor/test mode (not LIVE), skip payment validation- const isPaymentRequired = mode === FormMode.LIVE ? !!paymentBlock.required : false+ const isPaymentRequired = mode.value === FormMode.LIVE ? !!paymentBlock.required : false// Pass required refs if Stripe needs them now (unlikely for just intent creation)const paymentResult = await payment.processPayment(paymentBlock, isPaymentRequired)@@ -179,7 +185,7 @@ export function useFormManager(initialFormConfig, mode = FormMode.LIVE, optionsif (paymentBlock) {// In editor/test mode (not LIVE), skip payment validation- const isPaymentRequired = mode === FormMode.LIVE ? !!paymentBlock.required : false+ const isPaymentRequired = mode.value === FormMode.LIVE ? !!paymentBlock.required : falseconst paymentResult = await payment.processPayment(paymentBlock, isPaymentRequired)@@ -316,6 +322,8 @@ export function useFormManager(initialFormConfig, mode = FormMode.LIVE, options// UI-related propertiesdarkMode, // Dark mode settingsetDarkMode: (isDark) => { darkMode.value = isDark }, // Method to update dark mode+ mode, // Form mode setting (ref)+ setMode: (newMode) => { mode.value = newMode }, // Method to update form mode// Composables (Expose if direct access needed, often not necessary)structure,