Skip to content

Beautiful Open-Source Form Builder

Enhance form submission handling and input event management

Julien Nahuma140226313eb
diff --git a/client/components/forms/core/TextAreaInput.vue b/client/components/forms/core/TextAreaInput.vue
index bd4f6febc..0b12c3f59 100644
--- a/client/components/forms/core/TextAreaInput.vue
+++ b/client/components/forms/core/TextAreaInput.vue
@@ -62,6 +62,14 @@ export default {
})
const onEnterPress = (event) => {
+ // Command+Enter (Mac) or Ctrl+Enter (Windows/Linux) emits input-filled event
+ if (event.metaKey || event.ctrlKey) {
+ event.preventDefault()
+ context.emit('input-filled')
+ return false
+ }
+
+ // Regular Enter behavior
if (props.preventEnter) {
event.preventDefault()
return false
diff --git a/client/components/open/forms/OpenFormFocused.vue b/client/components/open/forms/OpenFormFocused.vue
index ea5de8230..fc2db0182 100644
--- a/client/components/open/forms/OpenFormFocused.vue
+++ b/client/components/open/forms/OpenFormFocused.vue
@@ -52,7 +52,13 @@
<div v-if="!props.formManager?.state.isSubmitted" class="mt-2 flex gap-2" :class="[getFieldAlignClasses(currentBlock), {'flex-col justify-normal! items-center': isLast &&form.use_captcha}]">
<slot name="submit-btn" v-if="isLast" :loading="isProcessing">
<CaptchaWrapper v-if="form.use_captcha" :form-manager="formManager" />
- <open-form-button :form="form" class="mt-0.5 px-6" :loading="isProcessing" @click.prevent="emit('submit')">
+ <open-form-button
+ native-type="button"
+ :form="form"
+ class="mt-0.5 px-6"
+ :loading="isProcessing"
+ @click.prevent.stop="handleSubmitClick"
+ >
{{ form.submit_button_text || $t('forms.buttons.submit') }}
</open-form-button>
</slot>
@@ -167,6 +173,17 @@ const handleNextClick = () => {
}
const onInputFilled = () => {
+ // On last page, submit the form instead of advancing
+ if (isLast.value) {
+ // Don't submit if already processing
+ if (isProcessing.value) {
+ return
+ }
+ emit('submit')
+ return
+ }
+
+ // On non-last pages, advance to next page
handleNextClick()
}
@@ -283,6 +300,16 @@ const goPrev = () => {
}
}
}
+const handleSubmitClick = (event) => {
+ // Prevent form submission if button is disabled/processing
+ if (isProcessing.value) {
+ event?.preventDefault()
+ return
+ }
+
+ emit('submit')
+}
+
const goNext = () => { if (!isLast.value) handleNextClick() }
// If block is text block, or any other block that has an align property, use the align property to determine the justify class
diff --git a/client/lib/forms/composables/useFormManager.js b/client/lib/forms/composables/useFormManager.js
index 438a694b9..c5a3c41a9 100644
--- a/client/lib/forms/composables/useFormManager.js
+++ b/client/lib/forms/composables/useFormManager.js
@@ -146,11 +146,18 @@ export function useFormManager(initialFormConfig, initialMode = FormMode.LIVE, o
* Navigates to the next page, handling validation and payment intent creation.
*/
const nextPage = async () => {
- if (state.isProcessing) return false
+ if (state.isProcessing) {
+ return false
+ }
+
+ // Check if we're already on the last page - if so, don't do anything (no validation, no advance)
+ const isCurrentlyLastPage = structure.value.isLastPage.value
+ if (isCurrentlyLastPage) {
+ return false
+ }
// Derive fields and conditions up-front so we can decide if we need a loading state
const currentPageFields = structure.value.getPageFields(state.currentPage)
- const isCurrentlyLastPage = structure.value.isLastPage.value
const paymentBlock = structure.value.currentPagePaymentBlock.value
// Determine if this step requires validation via validation helper filtering
@@ -169,7 +176,9 @@ export function useFormManager(initialFormConfig, initialMode = FormMode.LIVE, o
try {
// 1. Validate current page if needed
- if (needsValidation) await validation.validateCurrentPage(currentPageFields, strategy.value)
+ if (needsValidation) {
+ await validation.validateCurrentPage(currentPageFields, strategy.value)
+ }
// 2. Process payment (Create Payment Intent if applicable)
if (paymentBlock) {
@@ -190,7 +199,8 @@ export function useFormManager(initialFormConfig, initialMode = FormMode.LIVE, o
state.isProcessing = false
return true
- } catch {
+ } catch (error) {
+ console.error('[useFormManager] nextPage: Error occurred', error)
// Use validation composable's failure handler
validation.onValidationFailure({
fieldGroups: structure.value.fieldGroups.value, // Pass reactive groups
diff --git a/client/lib/forms/composables/useFormValidation.js b/client/lib/forms/composables/useFormValidation.js
index f7865ce2c..81cde58c5 100644
--- a/client/lib/forms/composables/useFormValidation.js
+++ b/client/lib/forms/composables/useFormValidation.js
@@ -32,7 +32,7 @@ export function useFormValidation(formConfig, form, managerState) {
try {
await formRef.value.validate(httpMethod, validationUrl, {}, fieldIds)
} catch (error) {
- console.error('Validation error:', error)
+ console.error('[useFormValidation] validateFields: Validation error (precognition)', error)
useAlert().formValidationError(error.data)
throw error
}