From 9514aacd8be40c690c6277cca28879c1902eed75 Mon Sep 17 00:00:00 2001 From: schatimo Date: Sun, 31 Dec 2023 15:37:49 +0100 Subject: [PATCH] fix scalar as list with multi selects --- demo/forms.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/demo/forms.py b/demo/forms.py index c94a60db..392a5ca7 100644 --- a/demo/forms.py +++ b/demo/forms.py @@ -127,6 +127,14 @@ class SelectForm(BaseModel): search_select_single: str = Field(json_schema_extra={'search_url': '/api/forms/search'}) search_select_multiple: list[str] = Field(json_schema_extra={'search_url': '/api/forms/search'}) + @field_validator('select_multiple', 'search_select_multiple', mode='before') + @classmethod + def correct_select_multiple(cls, v: list[str]) -> list[str]: + if isinstance(v, list): + return v + else: + return [v] + @router.post('/select', response_model=FastUI, response_model_exclude_none=True) async def select_form_post(form: Annotated[SelectForm, fastui_form(SelectForm)]):