Skip to content

Commit

Permalink
fix scalar as list with multi selects
Browse files Browse the repository at this point in the history
  • Loading branch information
schatimo committed Dec 31, 2023
1 parent cec25c6 commit 9514aac
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions demo/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]):
Expand Down

0 comments on commit 9514aac

Please sign in to comment.