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've been enjoying using yup to validate both forms and API requests, so I'd like to say a huge thank you in the first place! :)
Anyways, what I'm missing is a more canonical way of checking if a boolean is true that doing something like:
yup.boolean().oneOf([true]),
Although the above-mentioned snippet does the job perfectly, it feels to me like a workaround for missing functionality. And I believe it's quite common to require a boolean to be true (checking checkboxes with agreements, ...).
I know that changing how .required() works for booleans (to only accept true) values is not possible (backwards compatibility, ...).
What I'd suggest is to either create a general truthy() checker on the mixed() type which would check if the value passed is truthy as JavaScript evaluates it (e. g. everything except for null, undefined, 0, false and some other).
Or create an explicit isTrue() checked on the boolean() type which would simply check if the value is true.
If you'd be interested in adding this functionality to the API, I'd be happy to send a PR with whatever solution you'd prefer :)
The text was updated successfully, but these errors were encountered:
Hi :)
I've been enjoying using yup to validate both forms and API requests, so I'd like to say a huge thank you in the first place! :)
Anyways, what I'm missing is a more canonical way of checking if a boolean is
true
that doing something like:Although the above-mentioned snippet does the job perfectly, it feels to me like a workaround for missing functionality. And I believe it's quite common to require a boolean to be
true
(checking checkboxes with agreements, ...).I know that changing how
.required()
works for booleans (to only accepttrue
) values is not possible (backwards compatibility, ...).What I'd suggest is to either create a general
truthy()
checker on themixed()
type which would check if the value passed is truthy as JavaScript evaluates it (e. g. everything except fornull
,undefined
,0
,false
and some other).Or create an explicit
isTrue()
checked on theboolean()
type which would simply check if the value istrue
.If you'd be interested in adding this functionality to the API, I'd be happy to send a PR with whatever solution you'd prefer :)
The text was updated successfully, but these errors were encountered: