|
1 | 1 | from contextlib import asynccontextmanager
|
2 | 2 | from io import BytesIO
|
3 |
| -from typing import List, Tuple, Union |
| 3 | +from typing import List, Literal, Tuple, Union |
4 | 4 |
|
5 | 5 | import pytest
|
6 | 6 | from fastapi import HTTPException
|
7 | 7 | from fastui import components
|
8 | 8 | from fastui.forms import FormFile, Textarea, fastui_form
|
9 |
| -from pydantic import BaseModel |
| 9 | +from pydantic import BaseModel, Field |
10 | 10 | from starlette.datastructures import FormData, Headers, UploadFile
|
11 | 11 | from typing_extensions import Annotated
|
12 | 12 |
|
@@ -469,3 +469,29 @@ def test_form_textarea_form_fields():
|
469 | 469 | }
|
470 | 470 | ],
|
471 | 471 | }
|
| 472 | + |
| 473 | + |
| 474 | +class FormSelectMultiple(BaseModel): |
| 475 | + values: List[Literal['foo', 'bar']] = Field(title='Select Multiple', description='First Selector') |
| 476 | + |
| 477 | + |
| 478 | +def test_form_select_multiple(): |
| 479 | + m = components.ModelForm(model=FormSelectMultiple, submit_url='/foobar/') |
| 480 | + |
| 481 | + assert m.model_dump(by_alias=True, exclude_none=True) == { |
| 482 | + 'formFields': [ |
| 483 | + { |
| 484 | + 'description': 'First Selector', |
| 485 | + 'locked': False, |
| 486 | + 'multiple': True, |
| 487 | + 'name': 'values', |
| 488 | + 'options': [{'label': 'Foo', 'value': 'foo'}, {'label': 'Bar', 'value': 'bar'}], |
| 489 | + 'required': True, |
| 490 | + 'title': ['Select Multiple'], |
| 491 | + 'type': 'FormFieldSelect', |
| 492 | + } |
| 493 | + ], |
| 494 | + 'method': 'POST', |
| 495 | + 'submitUrl': '/foobar/', |
| 496 | + 'type': 'ModelForm', |
| 497 | + } |
0 commit comments