# Issue in making required field optional in ZOD? would you please tell me where is the issue in below code?

**URL:** <https://forum.codewithmosh.com/t/issue-in-making-required-field-optional-in-zod-would-you-please-tell-me-where-is-the-issue-in-below-code/26108>\
**Category:** React\
**Created:** [April 13, 2024, 8:20pm UTC](https://forum.codewithmosh.com/t/issue-in-making-required-field-optional-in-zod-would-you-please-tell-me-where-is-the-issue-in-below-code/26108 "2024-04-13T20:20:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravindranath4u](https://avatars.discourse-cdn.com/v4/letter/r/77aa72/32.png) [@ravindranath4u](https://forum.codewithmosh.com/u/ravindranath4u)\
**Post date:** [April 13, 2024, 8:20pm UTC](https://forum.codewithmosh.com/t/issue-in-making-required-field-optional-in-zod-would-you-please-tell-me-where-is-the-issue-in-below-code/26108/1 "2024-04-13T20:20:41Z")

</div>

const schema = z.object({  
workType: z.string().min(1, { message: “Please select work type” }),  
workSubType: z.string().min(1, { message: “Please select work sub type” }),  
workTypeDescriptions: z.string().min(1, { message: “Please select description” }),  
radioButtonSelection: z.enum([“Yes”, “No”], {errorMap: () =\> ({ message: “Please select an option” })}),  
policyNumber: z.string().refine((value , data) =\> {  
if (data.radioButtonSelection === “Yes”) {  
return typeof value === ‘string’ && value.length \>= 7;  
}  
return true;  
}, {message: ‘please enter policy number’, path:[‘policyNumber’]}).optional(),  
});
