Skip to content

Forms without interactivity

This page has no interactive render mode: it is rendered on the server, and its form posts to the server like any HTML form - which is also what a browser with script turned off gets. A FormName is all it takes. The page's [SupplyParameterFromForm] model binds what each control posts, and the form judges it on the server exactly as it would in the browser.

Submit it empty: the page comes back with every message in place. Type letters into Hours a week: model binding cannot read them, and the form shows them back with the reason. Country is a combobox: it posts the name you type, and the form turns it into the code it stands for. With nothing to click, what a click would show is shown already - a field that depends on another appears after the post that answered it.
Live form - posted, not interactive
Volunteer with us

Where you'd like to help

4 choices available

Address
View source
@page "/static-form"
@attribute [ExcludeFromInteractiveRouting]     @* Stays on the server in an interactive app *@

<BormView Definition="_schema" Model="Model" FormName="volunteer" OnValidSubmit="Received" SubmitText="Apply" />

@code {
    [SupplyParameterFromForm(FormName = "volunteer")]
    public VolunteerApplication? Model { get; set; }

    private BormDefinition _schema = default!;

    protected override void OnInitialized()
    {
        Model ??= new();
        _schema = BormBuilder.For<VolunteerApplication>()
            .Title("Volunteer with us")
            .Columns(2)
            .Field(x => x.FullName, f => f.Required().ColumnSpan(2))
            .Field(x => x.Email, f => f.Required().Email())
            // A text box that brings up the number pad, rather than a number box: a browser posts a number box holding
            // letters as nothing at all, so the text the user typed would be lost before the server could refuse it.
            .Field(x => x.Hours, f => f.Range(1, 40).As(BormFieldType.Text).InputMode("numeric"))
            .Field(x => x.Team, f => f.AsRadio()
                .Options(("events", "Events"), ("kitchen", "Kitchen"), ("drivers", "Drivers")).Required())
            .Field(x => x.Country, f => f.AsCombobox().Options([.. DemoDirectory.Countries]).Required())
            .Field(x => x.Newsletter)
            .Object(x => x.Address, a => a
                .Field(c => c.City, f => f.Required())
                .Field(c => c.PostCode, f => f.VisibleWhen("isNotEmpty({City})")))
            .Build();
    }

    private void Received(BormState state)
    {
        // ... save it, then send the user on: NavigationManager.NavigateTo("/thanks") ...
    }
}
An unhandled error has occurred. Reload 🗙