Skip to content

Custom error message shape #3264

Discussion options

You must be logged in to vote

Is this what you are looking for?

const FILE_SIZE_LIMIT = 123456789
const FileToUpload = z.instanceof( File ).superRefine( ( file, ctx ) => {
    if ( file.size < FILE_SIZE_LIMIT ) return true
    ctx.addIssue( {
        code: 'custom',
        message: `File size should be less than ${ FILE_SIZE_LIMIT } MB`,
        params: {
            id: 'uploaded_file_size',
            max: FILE_SIZE_LIMIT,
        },
    } )
} )

If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks friend! 🙏
https://github.com/sponsors/JacobWeisenburger

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by JacobWeisenburger
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@exelimpichment
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #3256 on February 23, 2024 13:05.