yup.number().nullable() does not allow `null` value

See original GitHub issue

yup.number().nullable() does not work for me in case of {field: {label: 'Some', value: null }}:

yup.object().shape({
  // ...
  field: yup.object().shape({
    label: yup.string(),
    value: yup.number().nullable()
  }),
});

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jquensecommented, Nov 20, 2018

yes we should update the docs!

I’m wondering, how can we enable null value for number() if it is not possible with nullable()?

the linked issue has a solution for that

0reactions
aaron-michauxcommented, Sep 19, 2021

What if we want to require a field to exist, and that it can take on null. nullable().required() would make sense. How would you achieve that at the moment?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I make a yup number accept nullable values?
Hi @xdumaine, thanks for your response. However, when the field is left as empty, the value that it returns is NaN instead of...
Read more >
yup.StringSchema.nullable JavaScript and Node.js ... - Tabnine
string() .nullable(true)
Read more >
Form schema
Form component renders a value to be updated and validated by child Fields. Forms can be thought of as <input/> s for complex...
Read more >
Formik Yup validation: string or null / boolean - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >
Yup | Best of JS
Yup is a schema builder for runtime value parsing and validation. ... When nullable() is set null is considered a valid value of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found