Expected string, received null
enyelsequeira opened this issue · comments
Hello, first of all thank you for creating the package it has saved me a lot of time.
I have a question, is there a way to change this error? I am using react hook form with it and here is my code. I have a validation schema using zod and have tried to get around without any luck, any chance there a way to change that error?
<PhoneInputWithCountry
name="mobile"
control={control}
rules={{ required: true }}
countrySelectComponent={PhoneCountry}
// flagComponent={FlagComponent}
international
limitMaxLength
placeholder="Enter phone number"
defaultCountry="US"
className="personal-input flex justify-between text-[#E0DFE1]"
/>
mobile: z
.string({
description: 'telephone number',
required_error: 'Telephone number is required',
})
.min(6, {
message: 'Telephone number must be at least 6 characters',
})
.max(15, {
message: 'Telephone number must be at most 15 characters',
})
.transform((value) => value.replace('+', ''))
.refine((value) => value !== '', {
message: 'Telephone number is required',
}),
Hi. I haven't used that validation library.
If you're validating a value then it will be undefined
when the input is empty.
is there any way to get around it? @catamphetamine
No
Or do something like value === undefined ? '' : value
.