Skip to content

Layout, groups & multi-selects

Forms are not always one field per row. Set Columns on the definition and ColumnSpan on individual fields to get a responsive grid that collapses to a single column on small screens. This form also shows a [Flags] enum and a plain List<TEnum> rendering as multi-selects, plus a typed nested object group.

Narrow the window and the two columns become one. Available on is a [Flags] enum and Preferred contact a List<ContactMethod>: both are a set of tick boxes in one <fieldset>, because the answers are a closed set either way. The address is a nested object - a group with a legend - laid out in two columns of its own with Attr("columns", 2). The browser can fill the whole form in: each field says what it is with Autocomplete(...), the phone brings up the phone keypad with InputMode("tel"), and the first name takes the focus as the form opens with Autofocus(). Reset puts back what the form started with. Every built-in control is on every field type, and fieldsets around runs of fields are on groups & custom layout.
Live form
Your profile

Available on
Preferred contact
Address

Tell us a little about yourself.

View source
@page "/layout"

<BormView Definition="_schema" Model="_model" OnValidSubmit="HandleSubmit"
          SubmitText="Save profile" ShowResetButton="true" />

@code {
    private readonly Profile _model = new();
    private BormDefinition _schema = default!;

    protected override void OnInitialized()
    {
        _schema = BormBuilder.For<Profile>()
            .Title("Your profile")
            .Columns(2)
            .Field(x => x.FirstName, f => f.Autocomplete("given-name").Autofocus())
            .Field(x => x.LastName, f => f.Autocomplete("family-name"))
            .Field(x => x.Email, f => f.Autocomplete("email"))
            .Field(x => x.Phone, f => f.Autocomplete("tel").InputMode("tel"))
            // A [Flags] enum becomes a multi-select automatically.
            .Field(x => x.Availability, f => f.ColumnSpan(2))
            // …and so does a plain List<TEnum>: the answers are a closed set either way, so it is a
            // set of tick boxes rather than a repeater of dropdowns.
            .Field(x => x.ContactMethods, f => f.ColumnSpan(2))
            // A nested object is a group with a legend. Attr("columns", 2) lays its own fields out in
            // two columns; ColumnSpan(2) lets the group take the form's whole width.
            .Object(x => x.Address, a => a
                .Field(p => p.Street, f => f.ColumnSpan(2).Autocomplete("street-address"))
                .Field(p => p.City, f => f.Autocomplete("address-level2"))
                .Field(p => p.PostCode, f => f.Autocomplete("postal-code"))
                .Field(p => p.Country, f => f.ColumnSpan(2).Autocomplete("country-name")),
                f => f.ColumnSpan(2).Attr("columns", 2))
            .Field(x => x.Bio, f => f.AsTextArea(4).ColumnSpan(2).Help("Tell us a little about yourself."))
            .Build();
    }
}
An unhandled error has occurred. Reload 🗙