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
When creating a form in HTML we can use the checkbox input, which naturally maps to a bool in Python:
<inputtype="checkbox" name="is_example" checked/>
Using FormData to submit that via a fetch or XMLHttpRequest request will follow the spec and product JSON in the request body like so:
{"is_example": "on"}
However, msgspec doesn't recognize it, and produces this error:
{"status_code":400,"detail":"Expected `bool`, got `str` - at `$.is_example`"}
This is very confusing, because a checkbox is essentially a bool, and other frameworks will usually do things like accept any truthy value. Luckily, there is a workaround right now by adding value="1" to the checkbox:
I suspect there are probably other values that work as well. But I'd argue that "1" is just as much a str or bool as "on" is, and the official standard has to use "on" for checkboxes since the form element was added to HTML 2 in 1995, so it should probably be supported natively.
The text was updated successfully, but these errors were encountered:
Description
When creating a form in HTML we can use the checkbox input, which naturally maps to a
bool
in Python:Using
FormData
to submit that via afetch
orXMLHttpRequest
request will follow the spec and product JSON in the request body like so:However, msgspec doesn't recognize it, and produces this error:
This is very confusing, because a checkbox is essentially a
bool
, and other frameworks will usually do things like accept any truthy value. Luckily, there is a workaround right now by addingvalue="1"
to the checkbox:I suspect there are probably other values that work as well. But I'd argue that
"1"
is just as much astr
orbool
as"on"
is, and the official standard has to use"on"
for checkboxes since theform
element was added to HTML 2 in 1995, so it should probably be supported natively.The text was updated successfully, but these errors were encountered: