Skip to content

Beautiful Open-Source Form Builder

Refactor form restart logic to include URL parameters

JhumanJ0b9ebdea75df
diff --git a/client/components/open/forms/OpenCompleteForm.vue b/client/components/open/forms/OpenCompleteForm.vue
index ab3a0ef84..5fbdcd36f 100644
--- a/client/components/open/forms/OpenCompleteForm.vue
+++ b/client/components/open/forms/OpenCompleteForm.vue
@@ -353,13 +353,16 @@ const triggerSubmit = () => {
})
}
-const restart = () => {
+const restart = async () => {
if (!formManager) return
- formManager.restart().then(() => {
- submittedData.value = null
- submissionId.value = null
- emit('restarted', true)
+ submittedData.value = null
+ submissionId.value = null
+ const queryString = route.fullPath.split('?')[1] || ''
+ await formManager.restart({
+ urlParams: new URLSearchParams(queryString),
+ submissionId: null
})
+ emit('restarted', true)
}
const editSubmission = () => {
diff --git a/client/lib/forms/composables/useFormManager.js b/client/lib/forms/composables/useFormManager.js
index d3e0b56a4..c3357398d 100644
--- a/client/lib/forms/composables/useFormManager.js
+++ b/client/lib/forms/composables/useFormManager.js
@@ -334,21 +334,20 @@ export function useFormManager(initialFormConfig, initialMode = FormMode.LIVE, o
}
}
- /** Resets the form to its initial state for refilling. */
- const restart = async () => {
+ /** Resets the form to its initial state for refilling with optional URL parameters. */
+ const restart = async (options = {}) => {
state.isSubmitted = false
state.currentPage = 0
state.isProcessing = false
- form.reset() // Reset vForm data
- form.errors.clear() // Clear vForm errors
timer.reset() // Reset timer via composable
timer.start() // Restart timer
- // Restart partial submission if enabled
- if (!import.meta.server && toValue(config).enable_partial_submissions && strategy.value.submission.enablePartialSubmissions) {
- partialSubmissionService.stopSync() // This will sync immediately before stopping
- partialSubmissionService.startSync() // Start fresh sync
- }
+ // Reinitialize the form to reapply URL parameters and default values
+ await initialize({
+ urlParams: options.urlParams,
+ submissionId: options.submissionId, // Explicitly pass submissionId (usually null)
+ skipPendingSubmission: true // Don't reload from localStorage on restart
+ })
}
// Clean up when component using the manager is unmounted