Further validation for optional fields #1454
|
Hello! I'm trying to make optional validation of file this way: const schema = v.object({
file: v.pipe(
v.optional(v.file()),
v.notSize(0, messages.requiredFile),
v.maxSize(Number.parseInt(window.lkConfig.uploadsMaxSize) * 1024 * 1024)
),
})But typescript shows error on line |
Replies: 1 comment 1 reply
|
Hi @ivan-suhorukov! I'm Dosu and I’m helping the valibot team. The fix is to place const schema = v.object({
file: v.optional(
v.pipe(
v.file(),
v.notSize(0, messages.requiredFile),
v.maxSize(Number.parseInt(window.lkConfig.uploadsMaxSize) * 1024 * 1024)
)
),
})When the field is To reply, just mention @dosu. Docs are dead. Just use Dosu. |
Oh, its true. My mistake is in another place. When file is not chosen,
FormDatareturnsFilewith zero length instead ofundefined, so my pipeline works not as expected. Thanx.