diff --git a/src/python-fastui/fastui/json_schema.py b/src/python-fastui/fastui/json_schema.py index e0ee88da..1b389de1 100644 --- a/src/python-fastui/fastui/json_schema.py +++ b/src/python-fastui/fastui/json_schema.py @@ -210,7 +210,7 @@ def json_schema_array_to_fields( items_schema = schema.get('items') if items_schema: items_schema, required = deference_json_schema(items_schema, defs, required) - for field_name in 'search_url', 'placeholder': + for field_name in 'search_url', 'placeholder', 'description': if value := schema.get(field_name): items_schema[field_name] = value # type: ignore if field := special_string_field(items_schema, loc_to_name(loc), title, required, True): diff --git a/src/python-fastui/tests/test_forms.py b/src/python-fastui/tests/test_forms.py index b0919fad..02e00cde 100644 --- a/src/python-fastui/tests/test_forms.py +++ b/src/python-fastui/tests/test_forms.py @@ -1,12 +1,12 @@ from contextlib import asynccontextmanager from io import BytesIO -from typing import List, Tuple, Union +from typing import List, Literal, Tuple, Union import pytest from fastapi import HTTPException from fastui import components from fastui.forms import FormFile, Textarea, fastui_form -from pydantic import BaseModel +from pydantic import BaseModel, Field from starlette.datastructures import FormData, Headers, UploadFile from typing_extensions import Annotated @@ -469,3 +469,29 @@ def test_form_textarea_form_fields(): } ], } + + +class FormSelectMultiple(BaseModel): + values: list[Literal['foo', 'bar']] = Field(title='Select Multiple', description='First Selector') + + +def test_form_select_multiple(): + m = components.ModelForm(model=FormSelectMultiple, submit_url='/foobar/') + + assert m.model_dump(by_alias=True, exclude_none=True) == { + 'formFields': [ + { + 'description': 'First Selector', + 'locked': False, + 'multiple': True, + 'name': 'values', + 'options': [{'label': 'Foo', 'value': 'foo'}, {'label': 'Bar', 'value': 'bar'}], + 'required': True, + 'title': ['Select Multiple'], + 'type': 'FormFieldSelect', + } + ], + 'method': 'POST', + 'submitUrl': '/foobar/', + 'type': 'ModelForm', + }