FastUI
FastUI copied to clipboard
Boolean value in update form is always required
class UpdateForm(BaseModel):
is_foo: bool
Renders to a required checkbox, so it always has to be "true" on submission!
workaround for now is to consider None as False. (so it makes checkbox optional), but that'd be cool to see this fixed :)
BoolUpdate = Annotated[bool | None, AfterValidator(lambda v: False if v is None else v)]
class UpdateForm(BaseModel):
is_foo: BoolUpdate = False
@ManiMozaffar,
Thanks for the report. Looks like a bug indeed!
Yup, this is a bug, the work around I've used is to implement a "yes, no" select, but that's very annoying.
Btw since Pydantic schema generator does not mark fields with default or default_factory as required, there seems to be a simple workaround for the issue:
class FormFieldsBool(BaseModel):
is_foo: bool = False
No need for custom type adapter, just initialize the field. This way behavior would be consistent across all field types.