Skip to content

[Bug]: zfd.checkbox() is not passing when type boolean is passed to it #457

@Dan503

Description

@Dan503

Which packages are impacted?

  • @rvf/react
  • @rvf/react-router
  • @rvf/zod
  • @rvf/yup
  • zod-form-data

What version of these packages are you using?

  • zod-form-data 3.0.0

Please provide a link to a minimal reproduction of the issue.

https://codesandbox.io/p/devbox/musing-cloud-8sdzs2?file=%2Fsrc%2FApp.tsx%3A3%2C1-13%2C1&workspaceId=ws_RWcC4PWu4DCakowNKjeNug

Steps to Reproduce the Bug or Issue

import { zfd } from 'zod-form-data'

const validationSchema = zfd.formData({
  isBoolean: zfd.checkbox(),
});

console.log(
  validationSchema.parse({
    isBoolean: true,
  })
);

This results in the following error:

ZodError: [
  {
    "code": "invalid_union",
    "errors": [
      [
        {
          "code": "invalid_value",
          "values": [
            "on"
          ],
          "path": [],
          "message": "Invalid input: expected \"on\""
        }
      ],
      [
        {
          "code": "invalid_value",
          "values": [
            null
          ],
          "path": [],
          "message": "Invalid input: expected undefined"
        }
      ]
    ],
    "path": [
      "isBoolean"
    ],
    "message": "Invalid input"
  }
]

Expected behavior

If I pass a boolean value to zfd.checkbox(), I expect it to pass validation.

Screenshots or Videos

No response

Platform

  • OS: Windows 11
  • Browser: Chrome, Firefox

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions