11<script setup lang="ts">
2+ import { computed , ref , watch } from ' vue'
23import type { DetailedFeedbackForm } from ' ../composables/useGlobalFeedback'
4+ import { isValidEmail } from ' ../functions/feedback-utils'
35import PersonalDetailsFields from ' ./PersonalDetailsFields.vue'
46
57interface Props {
@@ -15,8 +17,32 @@ interface Emits {
1517 submit: []
1618}
1719
18- defineProps <Props >()
20+ const props = defineProps <Props >()
1921const emit = defineEmits <Emits >()
22+
23+ const submitted = ref (false )
24+
25+ watch (
26+ () => props .modelValue ,
27+ (open ) => {
28+ if (open ) submitted .value = false
29+ },
30+ )
31+
32+ const qualityFeedbackError = computed (() =>
33+ submitted .value && ! props .detailsForm .qualityFeedback .trim () ? ' This field is required.' : undefined ,
34+ )
35+
36+ const useCaseError = computed (() =>
37+ submitted .value && ! props .detailsForm .useCase .trim () ? ' This field is required.' : undefined ,
38+ )
39+
40+ const emailError = computed (() => {
41+ if (props .detailsForm .email && ! isValidEmail (props .detailsForm .email )) {
42+ return ' Please enter a valid email address.'
43+ }
44+ return undefined
45+ })
2046 </script >
2147
2248<template >
@@ -35,31 +61,32 @@ const emit = defineEmits<Emits>()
3561 <v-textarea
3662 :model-value =" detailsForm.qualityFeedback"
3763 @update:model-value =" emit('update:form', 'qualityFeedback', $event)"
38- label =" How can we improve field boundaries?"
64+ label =" How can we improve field boundaries? * "
3965 hint =" Share what's good/bad and what would make them more useful to you"
4066 variant =" outlined"
4167 rows =" 4"
4268 auto-grow
43- required
4469 class =" mb-3"
70+ :error-messages =" qualityFeedbackError"
4571 ></v-textarea >
4672
4773 <v-textarea
4874 :model-value =" detailsForm.useCase"
4975 @update:model-value =" emit('update:form', 'useCase', $event)"
50- label =" How would you like to use field boundaries?"
76+ label =" How would you like to use field boundaries? * "
5177 hint =" Describe your specific use case and how field boundaries could be more useful to you"
5278 variant =" outlined"
5379 rows =" 3"
5480 auto-grow
55- required
5681 class =" mb-3"
82+ :error-messages =" useCaseError"
5783 ></v-textarea >
5884
5985 <PersonalDetailsFields
6086 :name =" detailsForm.name"
6187 :email =" detailsForm.email"
6288 :organization =" detailsForm.organization"
89+ :submitted =" submitted"
6390 @update:name =" emit('update:form', 'name', $event)"
6491 @update:email =" emit('update:form', 'email', $event)"
6592 @update:organization =" emit('update:form', 'organization', $event)"
@@ -72,9 +99,8 @@ const emit = defineEmits<Emits>()
7299 <v-btn
73100 color =" teal"
74101 variant =" flat"
75- :disabled =" !canSubmit"
76102 :loading =" isSubmitting"
77- @click =" emit('submit')"
103+ @click =" submitted = true; emit('submit')"
78104 >
79105 Submit
80106 </v-btn >
0 commit comments