Skip to content
This repository was archived by the owner on Jun 7, 2026. It is now read-only.
This repository was archived by the owner on Jun 7, 2026. It is now read-only.

Add class_name option for Models used in ModelForm #353

Description

@ibe-314

Currently when using ModelForm every form field is put into a new row. Here is an example:

grafik

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

grafik

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions