@@ -103,6 +103,24 @@ const EnterpriseContactForm = ({ strings }: EnterpriseContactFormProps) => {
103
103
}
104
104
}
105
105
106
+ const handleBlur =
107
+ ( field : keyof FormState ) =>
108
+ ( e : React . FocusEvent < HTMLInputElement | HTMLTextAreaElement > ) => {
109
+ const value = e . target . value
110
+
111
+ if ( field === "email" ) {
112
+ const emailError = validateEmail ( value )
113
+ if ( emailError ) setErrors ( ( prev ) => ( { ...prev , email : emailError } ) )
114
+ return
115
+ }
116
+ if ( field === "message" ) {
117
+ const messageError = validateMessage ( value )
118
+ if ( messageError )
119
+ setErrors ( ( prev ) => ( { ...prev , message : messageError } ) )
120
+ return
121
+ }
122
+ }
123
+
106
124
const validateEmail = ( email : string ) : string | undefined => {
107
125
const sanitized = sanitizeInput ( email )
108
126
@@ -190,6 +208,8 @@ const EnterpriseContactForm = ({ strings }: EnterpriseContactFormProps) => {
190
208
placeholder = { strings . placeholder . input }
191
209
value = { formData . email }
192
210
onChange = { handleInputChange ( "email" ) }
211
+ onBlur = { handleBlur ( "email" ) }
212
+ hasError = { ! ! errors . email }
193
213
disabled = { submissionState === "submitting" }
194
214
/>
195
215
{ errors . email && (
@@ -204,6 +224,8 @@ const EnterpriseContactForm = ({ strings }: EnterpriseContactFormProps) => {
204
224
placeholder = { strings . placeholder . textarea }
205
225
value = { formData . message }
206
226
onChange = { handleInputChange ( "message" ) }
227
+ onBlur = { handleBlur ( "message" ) }
228
+ hasError = { ! ! errors . message }
207
229
disabled = { submissionState === "submitting" }
208
230
className = "min-h-[120px]"
209
231
/>
0 commit comments