I am not able to submit my form for some reason

As the title says, I can't submit my form. No error is shown in the console but nothing happens. here is my form:
<UForm :schema="objectiveFormSchema" :state="formData" @submit="onSubmit" class="w-full flex flex-col gap-4">
<UFormGroup required class="px-4 py-4 border-b">
<div class="flex items-center">
<div class="w-1/2 pr-4">
<div class="flex items-center">
<h1 class="text-xl text-gray-800 font-bold">Title</h1>
<span class="text-red-500 ml-1">*</span>
</div>
<p class="text-sm text-gray-500 mt-1 whitespace-normal">Enter Article Title</p>
</div>
<div class="w-1/2">
<UInput placeholder="Enter Article Title" size="md" v-model="formData.title" class="w-full"/>
</div>
</div>
</UFormGroup>

<UFormGroup required class="px-4 py-4 border-b">
<div class="flex items-center">
<div class="w-1/2 pr-4">
<div class="flex items-center">
<h1 class="text-xl text-gray-800 font-bold">Description</h1>
</div>
<p class="text-sm text-gray-500 mt-1 whitespace-normal">Enter Article Description</p>
</div>
<div class="w-1/2">
<UTextarea placeholder="Enter Article Description" size="md" v-model="formData.description" class="w-full"/>
</div>
</div>
</UFormGroup>

<UFormGroup required class="px-4 py-4 border-b">
<div class="flex items-center">
<div class="w-1/2 pr-4">
<div class="flex items-center">
<h1 class="text-xl text-gray-800 font-bold">Learning Objectives</h1>
</div>
<p class="text-sm text-gray-500 mt-1 whitespace-normal">Enter key learning objectives</p>
</div>
<div class="w-1/2">
<UTextarea placeholder="Enter Learning Objectives" size="md" v-model="formData.objectives" class="w-full"/>
</div>
</div>
</UFormGroup>

<UFormGroup required class="px-4 py-4 border-b">
<div class="flex items-center">
<div class="w-1/2 pr-4">
<div class="flex items-center">
<h1 class="text-xl text-gray-800 font-bold">Audiences</h1>
</div>
<p class="text-sm text-gray-500 mt-1 whitespace-normal">Select one or more article audiences</p>
</div>
<div class="w-1/2">
<USelectMenu v-model="formData.audience" :options="audienceOptions" multiple placeholder="Select Audience" class="w-full"/>
</div>
</div>
</UFormGroup>

<UFormGroup required class="px-4 py-4 border-b">
<div class="flex items-center">
<div class="w-1/2 pr-4">
<div class="flex items-center">
<h1 class="text-xl text-gray-800 font-bold">Word Count</h1>
</div>
<p class="text-sm text-gray-500 mt-1 whitespace-normal">Enter the desired word count</p>
</div>
<div class="w-1/2">
<UInput type="number" placeholder="Enter Article Word Count" size="md" v-model="formData.wordCount" class="w-full"/>
</div>
</div>
</UFormGroup>

<UButton block class="text-center" icon="i-heroicons-arrow-right-16-solid" trailing type="submit">Continue
</UButton>
</UForm>
<UForm :schema="objectiveFormSchema" :state="formData" @submit="onSubmit" class="w-full flex flex-col gap-4">
<UFormGroup required class="px-4 py-4 border-b">
<div class="flex items-center">
<div class="w-1/2 pr-4">
<div class="flex items-center">
<h1 class="text-xl text-gray-800 font-bold">Title</h1>
<span class="text-red-500 ml-1">*</span>
</div>
<p class="text-sm text-gray-500 mt-1 whitespace-normal">Enter Article Title</p>
</div>
<div class="w-1/2">
<UInput placeholder="Enter Article Title" size="md" v-model="formData.title" class="w-full"/>
</div>
</div>
</UFormGroup>

<UFormGroup required class="px-4 py-4 border-b">
<div class="flex items-center">
<div class="w-1/2 pr-4">
<div class="flex items-center">
<h1 class="text-xl text-gray-800 font-bold">Description</h1>
</div>
<p class="text-sm text-gray-500 mt-1 whitespace-normal">Enter Article Description</p>
</div>
<div class="w-1/2">
<UTextarea placeholder="Enter Article Description" size="md" v-model="formData.description" class="w-full"/>
</div>
</div>
</UFormGroup>

<UFormGroup required class="px-4 py-4 border-b">
<div class="flex items-center">
<div class="w-1/2 pr-4">
<div class="flex items-center">
<h1 class="text-xl text-gray-800 font-bold">Learning Objectives</h1>
</div>
<p class="text-sm text-gray-500 mt-1 whitespace-normal">Enter key learning objectives</p>
</div>
<div class="w-1/2">
<UTextarea placeholder="Enter Learning Objectives" size="md" v-model="formData.objectives" class="w-full"/>
</div>
</div>
</UFormGroup>

<UFormGroup required class="px-4 py-4 border-b">
<div class="flex items-center">
<div class="w-1/2 pr-4">
<div class="flex items-center">
<h1 class="text-xl text-gray-800 font-bold">Audiences</h1>
</div>
<p class="text-sm text-gray-500 mt-1 whitespace-normal">Select one or more article audiences</p>
</div>
<div class="w-1/2">
<USelectMenu v-model="formData.audience" :options="audienceOptions" multiple placeholder="Select Audience" class="w-full"/>
</div>
</div>
</UFormGroup>

<UFormGroup required class="px-4 py-4 border-b">
<div class="flex items-center">
<div class="w-1/2 pr-4">
<div class="flex items-center">
<h1 class="text-xl text-gray-800 font-bold">Word Count</h1>
</div>
<p class="text-sm text-gray-500 mt-1 whitespace-normal">Enter the desired word count</p>
</div>
<div class="w-1/2">
<UInput type="number" placeholder="Enter Article Word Count" size="md" v-model="formData.wordCount" class="w-full"/>
</div>
</div>
</UFormGroup>

<UButton block class="text-center" icon="i-heroicons-arrow-right-16-solid" trailing type="submit">Continue
</UButton>
</UForm>
and my onSubmit:
async function onSubmit(event: FormSubmitEvent<schemaType>) {
console.log("calling")
props.callback(event.data);
}
async function onSubmit(event: FormSubmitEvent<schemaType>) {
console.log("calling")
props.callback(event.data);
}
5 Replies
kapa.ai
kapa.ai7d ago
Hi @Just Simeon. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided in your code and the knowledge sources available, there are a few potential reasons why your form might not be submitting. Let's go through some possible issues: 1. Schema Definition: You're using a :schema="objectiveFormSchema" prop on your UForm component, but you haven't shown the definition of objectiveFormSchema in your code snippet. Make sure you have properly defined this schema using a validation library like Yup, Zod, or others as mentioned in the Form component documentation (https://ui.nuxt.com/components/form#usage). 2. State Reactivity: Ensure that your formData object is properly reactive. It should be defined using ref() or reactive() from Vue's Composition API. 3. Event Handling: Your onSubmit function is correctly defined to handle the FormSubmitEvent, but make sure it's properly bound to the component's setup function. 4. Validation Errors: If there are validation errors, the form might not submit. Check if there are any validation errors by adding an error handler:
<UForm
:schema="objectiveFormSchema"
:state="formData"
@submit="onSubmit"
@error="onError"
class="w-full flex flex-col gap-4"
>
<!-- ... rest of your form ... -->
</UForm>

<UForm
:schema="objectiveFormSchema"
:state="formData"
@submit="onSubmit"
@error="onError"
class="w-full flex flex-col gap-4"
>
<!-- ... rest of your form ... -->
</UForm>

And in your script:
function onError(error: FormErrorEvent) {
console.log("Form validation errors:", error.errors);
}

function onError(error: FormErrorEvent) {
console.log("Form validation errors:", error.errors);
}

5. Console Logging: Add more console logs in your onSubmit function to ensure it's being called:
async function onSubmit(event: FormSubmitEvent<schemaType>) {
console.log("Form submitted", event.data);
props.callback(event.data);
}

async function onSubmit(event: FormSubmitEvent<schemaType>) {
console.log("Form submitted", event.data);
props.callback(event.data);
}

6. Callback Function: Ensure that the callback prop you're calling in onSubmit is properly defined and passed to your component. 7. Form Events: By default, the Form component validates on submit, blur, input, and change events. If you want to change this behavior, you can use the validate-on prop as mentioned in the Input events documentation (https://ui.nuxt.com/components/form#input-events). If none of these solve your issue, you might want to try using the validate prop instead of schema for custom validation logic, as shown in the Custom validation documentation (https://ui.nuxt.com/components/form#custom-validation). Remember to check your browser's network tab to see if any requests are being made when you submit the form, and also check for any errors in the browser console. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai7d ago
<@294593079812292609> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Just Simeon
Just SimeonOP7d ago
@kapa.ai I am getting a formValidationError but the output makes no sense: Form validation errors: Array: (3) ["Object", "Object", "Object"]
kapa.ai
kapa.ai7d ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Based on the error output you're seeing, it appears that the form validation is indeed catching errors, but the console output is not displaying the full error details. This is likely due to how the errors are being logged. Let's address this issue and improve the error handling to get more meaningful information. To get a better understanding of the validation errors, you can modify your error handling as follows:
function onError(error: FormErrorEvent) {
console.log("Form validation errors:", error.errors);
error.errors.forEach((err, index) => {
console.log(`Error ${index + 1}:`, {
path: err.path,
message: err.message
});
});
}
function onError(error: FormErrorEvent) {
console.log("Form validation errors:", error.errors);
error.errors.forEach((err, index) => {
console.log(`Error ${index + 1}:`, {
path: err.path,
message: err.message
});
});
}
This approach will log each error object separately, showing the path (which field caused the error) and the message (what the error is). You can add this error handling to your form as mentioned in the Form component documentation (https://ui.nuxt.com/components/form#error-event):
<UForm
:schema="objectiveFormSchema"
:state="formData"
@submit="onSubmit"
@error="onError"
class="w-full flex flex-col gap-4"
>
<!-- Your form fields -->
</UForm>
<UForm
:schema="objectiveFormSchema"
:state="formData"
@submit="onSubmit"
@error="onError"
class="w-full flex flex-col gap-4"
>
<!-- Your form fields -->
</UForm>
If you're using a custom validation function instead of a schema, make sure your validation function is returning an array of FormError objects with the correct structure. Here's an example based on the Custom validation documentation (https://ui.nuxt.com/components/form#custom-validation):
const validate = (state: any): FormError[] => {
const errors = []
if (!state.title) errors.push({ path: 'title', message: 'Title is required' })
if (!state.description) errors.push({ path: 'description', message: 'Description is required' })
// Add more validation rules as needed
return errors
}
const validate = (state: any): FormError[] => {
const errors = []
if (!state.title) errors.push({ path: 'title', message: 'Title is required' })
if (!state.description) errors.push({ path: 'description', message: 'Description is required' })
// Add more validation rules as needed
return errors
}
Then use this validate function in your form:
<UForm
:validate="validate"
:state="formData"
@submit="onSubmit"
@error="onError"
class="w-full flex flex-col gap-4"
>
<!-- Your form fields -->
</UForm>
<UForm
:validate="validate"
:state="formData"
@submit="onSubmit"
@error="onError"
class="w-full flex flex-col gap-4"
>
<!-- Your form fields -->
</UForm>
By implementing these changes, you should be able to see more detailed and meaningful error messages when form validation fails. This will help you identify which fields are causing validation errors and what the specific issues are. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai7d ago
<@294593079812292609> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Want results from more Discord servers?
Add your server