Enhance Form Management with Dynamic Configuration Updates
- Added a new watcher in `OpenCompleteForm.vue` to monitor changes to the form prop and update the form manager accordingly, ensuring that the form manager reflects the latest configuration. - Introduced an `updateConfig` method in `useFormManager.js` to handle updates to the form configuration, resetting the form state and reinitializing with the new config. This improves the flexibility and responsiveness of the form management system. These changes aim to enhance the user experience by ensuring that form updates are seamlessly integrated into the form management workflow, allowing for more dynamic interactions.
This commit is contained in:
parent
7918134c08
commit
591d21d888
|
|
@ -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
|
// Share the structure service with the working form store only when in admin edit context
|
||||||
watch(() => formManager?.strategy?.value?.admin?.showAdminControls, (showAdminControls) => {
|
watch(() => formManager?.strategy?.value?.admin?.showAdminControls, (showAdminControls) => {
|
||||||
if (workingFormStore && formManager?.structure && showAdminControls) {
|
if (workingFormStore && formManager?.structure && showAdminControls) {
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,26 @@ export function useFormManager(initialFormConfig, mode = FormMode.LIVE, options
|
||||||
const payment = useFormPayment(config, form)
|
const payment = useFormPayment(config, form)
|
||||||
const submission = useFormSubmission(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.
|
* Initializes the form: loads data, resets state, starts timer.
|
||||||
* @param {Object} options - Initialization options (passed to useFormInitialization).
|
* @param {Object} options - Initialization options (passed to useFormInitialization).
|
||||||
|
|
@ -303,6 +323,7 @@ export function useFormManager(initialFormConfig, mode = FormMode.LIVE, options
|
||||||
|
|
||||||
// Core Methods
|
// Core Methods
|
||||||
initialize,
|
initialize,
|
||||||
|
updateConfig, // New method to update form config
|
||||||
nextPage,
|
nextPage,
|
||||||
previousPage,
|
previousPage,
|
||||||
submit,
|
submit,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue