Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support tuples in forms #52

Merged
merged 10 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'):
samuelcolvin marked this conversation as resolved.
Show resolved Hide resolved
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