Skip to content

Commit

Permalink
Support tuples in forms.
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfDWyc authored Dec 2, 2023
1 parent 239005c commit 91a3c9a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/demo/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ class BigModel(BaseModel):
dob: date = Field(title='Date of Birth', description='Your date of birth, this is required hence bold')
size: SizeModel

address: tuple[
Annotated[str, Field(description='Main Address')],
Annotated[str | None, Field(description='Secondary Address')],
Annotated[str | None, Field(description='Business Address')]
]

@field_validator('name')
def name_validator(cls, v: str | None) -> str:
if v and v[0].islower():
Expand Down
5 changes: 5 additions & 0 deletions python/fastui/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ def json_schema_array_to_fields(
items_schema[field_name] = value # type: ignore
if field := special_string_field(items_schema, loc_to_name(loc), title, required, True):
return [field]
elif 'minItems' in schema and schema.get('minItems') == schema.get('maxItems'):
if items := schema.get('prefixItems'):
for i, item in enumerate(items):
yield from json_schema_any_to_fields(item, loc + [i], title, required, defs)
return
raise NotImplementedError('todo')


Expand Down

0 comments on commit 91a3c9a

Please sign in to comment.