-
Notifications
You must be signed in to change notification settings - Fork 335
Open
Description
Currently when using ModelForm every form field is put into a new row. Here is an example:
The form above is generated using FastUIs ModelForm with the following pydantic Model:
class ExampleModel(BaseModel):
first_name: Optional[str] = Field(
None, title='First Name'
)
family_name: Optional[str] = Field(
None, title='Family Name'
)
birth_date: Optional[date] = Field(None, title='Birth Date')
remark: Optional[str] = Field(None, title='Remark')
info: Annotated[Optional[str], Textarea(rows=5)] = Field(None, description='Optional free text information about you.')
repo: str = Field(json_schema_extra={'placeholder': '{org}/{repo}'}, title='GitHub repository')
I would like to allign mutliple fields in one row using Bootstraps row and column functionality. I was not able to do this using ModelForm, however I found a solution using the Form class from fastui.components.forms:
manuel_model = c.Form(
form_fields=[
FormFieldInput(
name="first_name",
title="First Name",
class_name="+ col-sm-4",
),
FormFieldInput(
name="family_name",
title="Family Name",
class_name="+ col-sm-4",
),
FormFieldInput(
name="birth_date",
title="Birth Date",
html_type="date",
class_name="+ col-sm-4",
),
FormFieldInput(
name="remark",
title="Remark",
class_name="+ col-sm-6",
),
FormFieldTextarea(
name="info",
title="Info",
class_name="+ col-sm-6",
),
FormFieldInput(
name="repo",
title="GitHub repository",
class_name="+ col-sm-12",
)
],
submit_url="/api/login",
class_name="+ row",
)
which results in
I looked into the code of ModelForm, where the model_json_schema_to_fields function renders the Pydantic Model. Is there currently some possiility to add class_name attributes to the ModelForm fields? Or some other possibility to get the second layout using the ModelForm class?
adknaupp
Metadata
Metadata
Assignees
Labels
No labels

