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
Do you want to request a feature or report a bug? Feature
What is the current behavior? "on" is no longer cast as true for Boolean fields.
What is the expected behavior? "on" and "off" should be cast as true/false like "yes" and "no"
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version. 5.6.6
It looks like in Mongoose 5.X only specific string values are permitted to be cast as Boolean. The default value for a checkbox in HTML spec is "on".
By default, unchecked checkboxes simply do not pass a value when forms are serialized but it might make sense to include an "off" counterpart for falsey conversion.
Thoughts? This can improve native compatibility with form submissions from HTML forms. I am not certain of potential negative impacts. This also restores Pre-5.X functionality for input checkbox form submissions while maintaining the improvements in boolean casting introduced.
While I agree that converting any non falsy value to true is too permissive, "on" and "off" are clearly boolean values.
We'll consider adding this in a minor release since it is fairly common. However, adding support for 'on/off' is a two-liner, see boolean schematype docs.
vkarpov15
added
help
This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
and removed
enhancement
This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
labels
May 18, 2021
Do you want to request a feature or report a bug? Feature
What is the current behavior? "on" is no longer cast as true for Boolean fields.
What is the expected behavior? "on" and "off" should be cast as true/false like "yes" and "no"
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version. 5.6.6
It looks like in Mongoose 5.X only specific string values are permitted to be cast as Boolean. The default value for a checkbox in HTML spec is "on".
By default, unchecked checkboxes simply do not pass a value when forms are serialized but it might make sense to include an "off" counterpart for falsey conversion.
Thoughts? This can improve native compatibility with form submissions from HTML forms. I am not certain of potential negative impacts. This also restores Pre-5.X functionality for input checkbox form submissions while maintaining the improvements in boolean casting introduced.
While I agree that
converting any non falsy value to true
is too permissive, "on" and "off" are clearly boolean values.Related:
#5344 (comment)
The text was updated successfully, but these errors were encountered: