You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanna make a schema where at least 1 field is required. I know I can use refine but I think I can avoid it...
I've tried below a strategy but it's lacking. I've accomplished validating either one. But I am lacking a validation for when the user leaves BOTH empty. Any ideas?
The real complication is that the form consider null or empty string to be as EMPTY values. So, that's where I gotta pass these things through a truthy check to make sure there's a value in either one....
Would love some help :)
export const useCommentSchema = () => {
return z.object({
comment: z
.string()
.min(
30,
translate("General.Validations.MinCharacters").replace("X", "30")
)
.max(250, translate("General.Validations.MaxExceeded"))
.regex(CommentBoxWithEnglish, translate("General.Validations.Regex")),
});
};
export const useMyFileSchema = () => {
return z.object({ file: useFileSchema(MAX_FILE_SIZE).nullable() });
};
export const useApplicationSchema = () => {
return useCommentSchema()
.merge(useMyFileSchema()) ////// This right has to check that both aren't empty. not empty string, not null.
.or(useCommentSchema()) // Can do either this
.or(useMyFileSchema()); // Or this
};
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello
I wanna make a schema where at least 1 field is required. I know I can use refine but I think I can avoid it...
I've tried below a strategy but it's lacking. I've accomplished validating either one. But I am lacking a validation for when the user leaves BOTH empty. Any ideas?
The real complication is that the form consider null or empty string to be as EMPTY values. So, that's where I gotta pass these things through a truthy check to make sure there's a value in either one....
Would love some help :)
Beta Was this translation helpful? Give feedback.
All reactions