I have simple input that is handled by react-hook-form
I have radio-buttons that I determin what is language that I make input’s value for and in the end I assume that I make just request to the server and send the content that I typed in the input in json form like
const nameValue = {
en: 'Hi there',
ar: 'مرحبا'
}
and the schema that I made is something like this:
const createDeviceCategoryFormSchema = z.object({
deviceCategory: z
.string({
required_error: 'Select the category of the device',
})
.refine((value) => value.length > 0, {
message: 'Select the company of device-category',
}), // it must be object converted to string
name: z
.string({ required_error: 'You need to fill this field' })
.min(3, 'Device-category name must be greater than 3 characters')
.max(25, 'Device-category name must be lower than 25 characters'),
image: z
.instanceof(FileList)
.refine(
(files) => {
return files.length === 1;
},
{
message: `You should select only one file`,
},
)
.refine(
(files) => {
if (files.length === 0) return true;
return (
files.item(0) &&
files.item(0)?.size <= fileConditions.CompanyImage.maxSize
);
},
{
message: `Maximum allowed file size is: ${fileConditions.CompanyImage.maxSize}`,
},
)
.refine(
(files) => {
if (files.length === 0) return true;
return (
files.item(0) &&
files.item(0)?.type.split('/')[1].toLowerCase() === 'png'
);
},
{
message: `The allowed image file type is "png"`,
},
),
});
Here name
is property attached to single input field, I need to make this property’ value change from language to another based on radio-buttons that I mentioned earlier, So How can I make this with zod and reac-hook-form (Without making multiple input fields!)