Skip to content

Commit

Permalink
Fix description for array-like fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sergue1 committed Feb 12, 2024
1 parent d3a8e6c commit b9bf601
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/python-fastui/fastui/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
30 changes: 28 additions & 2 deletions src/python-fastui/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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',
}

0 comments on commit b9bf601

Please sign in to comment.