Klyroo.Form.Core
0.1.0-preview.2
dotnet add package Klyroo.Form.Core --version 0.1.0-preview.2
NuGet\Install-Package Klyroo.Form.Core -Version 0.1.0-preview.2
<PackageReference Include="Klyroo.Form.Core" Version="0.1.0-preview.2" />
<PackageVersion Include="Klyroo.Form.Core" Version="0.1.0-preview.2" />
<PackageReference Include="Klyroo.Form.Core" />
paket add Klyroo.Form.Core --version 0.1.0-preview.2
#r "nuget: Klyroo.Form.Core, 0.1.0-preview.2"
#:package Klyroo.Form.Core@0.1.0-preview.2
#addin nuget:?package=Klyroo.Form.Core&version=0.1.0-preview.2&prerelease
#tool nuget:?package=Klyroo.Form.Core&version=0.1.0-preview.2&prerelease
Klyroo.Form
Schema-driven forms, validation and wizards for .NET developers, with a headless engine and Blazor components.
You declare a form from a C# model with FormSchema.For<TModel>: fields, conditions, rules, steps and sections, written with refactor-safe expressions and checked by the compiler. A FormController<TModel> holds its state: values typed as your members, touched fields, errors, dirty tracking and step navigation. The controller has no UI dependency, so the same schema can be unit tested, run in a view model, or rendered by the Blazor components. The Blazor layer builds on Klyroo.UI and runs in Interactive Server, WebAssembly and Auto render modes, and in .NET MAUI Blazor Hybrid.
Every page of the documentation uses the typed API except one. A form that only exists as data at runtime, such as one stored as JSON or in a database, uses the runtime mode in Klyroo.Form.Dynamic, which is documented apart in Forms defined at runtime.
Features
- Typed schema:
FormSchema.For<Order>(s => { s.Field(o => o.Seats, f => f.Range(1, 500)); ... })declares fields from the members of a C# class and returns a handle per field, so a condition points at an earlier field through a captured local andcontroller.Get(seats)is anint. Kind-specific settings (AsTextarea,Range,Options,AsSwitch) are extension methods constrained on the type of the value, so a wrong kind does not compile.Group,List,MultiSelect,StepandSectiondeclare nested objects, repeatable rows, multiple choice, wizards and pages. - Headless controller:
FormController<TModel>manages values, touched state, errors, dirty tracking, steps and submission with no UI dependency, andKlyroo.Form.Coreis NativeAOT compatible. - Typed components:
KlyFormEngine<TModel>andKlyFormPage<TModel>render aFormSchema<TModel>(or aFormController<TModel>) with aModel, and inferTModelfrom the markup.OnSavereceives the model,OnSubmitis raised with it, and a submit writes the values into the model you gave, all or nothing.KlyFormFieldViewdraws one field for a layout of your own, andKlyFieldTemplatedraws the control of one field with a typedFormControlContext<TValue>. - Validation: required and required-when checks, number bounds, password requirements, typed
RuleandRuleAsyncrules with a pending state (debounced, stale runs cancelled, awaited by submit), four validation modes and three triggers (blur, input, submit). - Model binding that cannot lose data: values move between the form and the model with culture-independent conversions (a
long, adecimaland adoublekeep every digit), a write into a model is all or nothing and rolls back when the save fails, and a value the user did not change keeps its ticks, kind and offset.Klyroo.Form.DataAnnotationsreads[Required],[Range],[Display]and the other attributes into a typed schema, and runsIValidatableObjectat submit. - Server errors:
SetErrorattaches a message to a field, optionally blocking submission until the user edits it. - Conditional fields:
VisibleWhen,Required(condition),DisabledWhenandskipWhenare plain delegates evaluated against the controller, and hidden fields, the children of hidden containers and the fields of skipped steps are left out of validation and of the model. - Dirty tracking: the controller compares values with an initial snapshot, resets a field or a section, and takes a new snapshot after a successful submit.
- Wizards and pages: multi-step forms with skippable steps and async before-next hooks, and sectioned pages that show a completion status per section.
- Extensible:
KlyFieldTemplateswaps the control of a typed field for your markup,AsCustom(key)plusCustomField<TValue>(key, renderer)registers one for the whole app, andFormFileValuefields are checked forAccept,MaxFileSizeand multiple files in the core. - Localization: the built-in texts and validation messages follow the Klyroo.UI locale in twelve languages (English and French reviewed, the rest drafts),
AddKlyrooForm(f => f.Texts("fr", t => t with { ... }))changes them, andFormMessagesworks without Blazor. - Unsaved changes:
KlyFormNavigationGuardblocks navigation while the form is dirty, andExportDraft()andRestoreDraft()keep a draft across a reload with the original baseline, so the restored draft is still dirty. - Overlays:
FormService.CreateFormAsync<TModel>opens a form in a modal dialog, a side drawer or a fullscreen view hosted byKlyFormProvider(onKlyModalandKlySlideover: focus trap, Escape, focus restored) and returns the result as a task (FormSubmitOutcome<TModel>with the submitted model). - Agent ready:
FormController<TModel>(like the runtimeDynamicFormController) implementsIFormRuntime, which lists the fields asIFormFieldAccesswith JSON read and write (numbers keep their exact digits, a choice matches by value or label), so an agent bridge drives a form without knowing its model type. - Runtime mode: when the fields are only known at runtime,
DynamicFormSchemaandDynamicFieldSchema(namespaceKlyroo.Form.Dynamic) describe the form as data, with values keyed by name, on the same engine.FormFieldKindhas 33 values, andKlyDynamicFormEngineandKlyDynamicFormPagerender each one. See Forms defined at runtime.
Packages
| Package | Description |
|---|---|
Klyroo.Form.Core |
Headless engine: the typed FormSchema and FormController<TModel>, and for forms defined at runtime DynamicFormSchema, DynamicFormController and DynamicFormService. No UI dependency, trimmable, NativeAOT compatible. |
Klyroo.Form |
Blazor components KlyFormEngine<TModel>, KlyFormPage<TModel>, KlyFormFieldView<TModel>, KlyFieldTemplate and KlyFormProvider, FormService, and the AddKlyrooForm() registration, plus KlyDynamicFormEngine, KlyDynamicFormPage and KlyDynamicFieldView for the runtime mode. Builds on Klyroo.UI and references Klyroo.Form.Core. |
Klyroo.Form.DataAnnotations |
Builds a typed schema from a C# model and its DataAnnotations attributes, and runs IValidatableObject and your own validation attributes at submit. References Klyroo.Form.Core only, so it also works without Blazor. |
For native .NET MAUI apps without a BlazorWebView, the repository also includes Klyroo.Form.Maui (built from source over Klyroo.Form.Core and Klyroo.UI.Maui).
Prerequisites
To use the library in an app:
- The .NET 11 SDK, and an app that targets
net11.0. The packages are prereleases, so everydotnet add packagecommand needs--prerelease. Klyroo.Form.Corealone (the form controller) runs in any .NET 11 app, with no other dependency.- A Blazor app for
Klyroo.Form: a Blazor Web App or a .NET MAUI Blazor Hybrid app. Typing, validation feedback, steps and submit need an interactive render mode (Interactive Server, WebAssembly or Auto). In a WebAssembly or Auto app, register the services in the server project and in the.Clientproject. - Klyroo.UI set up in the app.
Klyroo.Formbrings the Klyroo.UI package, andAddKlyrooForm()registers its services, but the layout still needs the Klyroo.UI stylesheets in<head>and<KlyApp>around the body, as described in the Klyroo.UI installation. <KlyFormProvider>in the layout if you open forms as overlays withFormService(orDynamicFormServicein the runtime mode).- A browser with the native popover API, which Klyroo.UI uses: Chrome and Edge 114, Safari 17 or Firefox 125, or later. In a .NET MAUI app, that means iOS or Mac Catalyst 17, or an Android System WebView 114 or later.
- Network access on the first build only if your app self-hosts web fonts (
KlyrooFont), uses icons outside the built-in set, or compiles Tailwind (KlyrooTailwind): the build downloads them once and caches them underobj/klyroo. Node.js is not needed.
To build this repository you need the .NET 11 SDK (a newer SDK works too, see global.json) and a clone of klyroo-ui in the same parent folder: some projects reference it by relative path (../klyroo-ui/...). See Contributing.
Installation
dotnet add package Klyroo.Form --prerelease
For the engine alone, without Blazor, install Klyroo.Form.Core instead.
Register the services in Program.cs (or MauiProgram.cs). It also registers Klyroo.UI:
using Klyroo.Form;
builder.Services.AddKlyrooForm();
Add the namespace to _Imports.razor:
@using Klyroo.Form
The runtime mode lives in its own namespace, Klyroo.Form.Dynamic: add it only where you use that mode.
Load the stylesheets in App.razor. The theme tokens come from Klyroo.UI and the form classes from this package:
<link rel="stylesheet" href="@Assets["_content/Klyroo.UI/klyroo.preflight.css"]" />
<link rel="stylesheet" href="@Assets["_content/Klyroo.UI/klyroo.css"]" />
<link rel="stylesheet" href="@Assets["_content/Klyroo.Form/klyroo-form.css"]" />
Quick start
Headless: declare a form from a model, drive it with a controller.
using Klyroo.Form;
public sealed class Contact
{
public string Name { get; set; } = "";
public string Email { get; set; } = "";
public Topic Topic { get; set; }
public string? Message { get; set; }
}
public enum Topic { Sales, Support }
var schema = FormSchema.For<Contact>(s =>
{
s.FormKey = "contact";
s.Field(c => c.Name, f => f.Required());
s.Field(c => c.Email, f => f.Required().Rule(e => e.Contains('@'), "Enter a valid email address"));
});
var name = schema.Field(c => c.Name);
var email = schema.Field(c => c.Email);
var form = new FormController<Contact>(schema);
form.Set(name, "Alice", markTouched: true);
form.Set(email, "alice", markTouched: true);
Console.WriteLine(form.GetError(email)); // Enter a valid email address
Console.WriteLine(await form.SubmitAsync()); // False
form.Set(email, "alice@example.com");
Console.WriteLine(await form.SubmitAsync((contact, ct) =>
{
Console.WriteLine($"Send a reply to {contact.Email}");
return Task.FromResult(true);
})); // True
Console.WriteLine(form.IsDirty); // False
Blazor: render the same schema with KlyFormEngine<TModel>. It infers TModel from Schema and Model, and the form writes the values into _contact when it submits.
@page "/contact"
@rendermode InteractiveServer
@inject IContactApi Api
<KlyFormEngine TModel="Contact" Schema="_schema" Model="_contact" SubmitLabel="Send" OnSave="SaveAsync" OnSubmit="Sent" />
@if (_sentTo is not null)
{
<p>Thanks, we will write to @_sentTo.</p>
}
@code {
private readonly Contact _contact = new();
private string? _sentTo;
// Keep the schema in a field: a new instance makes the component start a new controller.
private static readonly FormSchema<Contact> _schema = FormSchema.For<Contact>(s =>
{
s.Title = "Contact us";
s.Field(c => c.Name, f => f.Required());
s.Field(c => c.Email, f => f.Required().Rule(e => e.Contains('@'), "Enter a valid email address"));
s.Field(c => c.Topic);
s.Field(c => c.Message, f => f.Required().AsTextarea().MaxLength(500));
});
private async Task<bool> SaveAsync(Contact contact, CancellationToken ct) => await Api.SendAsync(contact, ct);
private void Sent(Contact contact) => _sentTo = contact.Email;
}
Api stands for your own service. Keep the schema in a field or a static member. KlyFormEngine<TModel> creates a new controller whenever it receives a different FormSchema<TModel> instance, which discards what the user typed. TModel="Contact" is written out because Razor cannot infer it when OnSubmit is a method group. A form that is not known until runtime is declared with the runtime mode instead: see Forms defined at runtime.
Documentation
| Getting started | Step-by-step first integration |
| Guides | Task-oriented recipes with the typed API |
| Forms defined at runtime | The runtime mode, for forms stored as data |
| Concepts | How the library works |
| Platforms | Render modes, .NET MAUI, NativeAOT |
| API reference | Every public type and member |
| FAQ | Troubleshooting and limitations |
Compatibility
- .NET 11 SDK.
Klyroo.Form.Coretargetsnet11.0, has no dependencies, is marked trimmable and AOT compatible, and a console app that references it publishes and runs withPublishAot.Klyroo.Formworks in Interactive Server, Interactive WebAssembly and Interactive Auto render modes. In Static SSR the markup renders but the controls are not interactive.Klyroo.Formdeclaresbrowser,ios,android,maccatalystandwindowsas supported platforms for .NET MAUI Blazor Hybrid. The test suite runs in bUnit, not on devices.Klyroo.Formis marked trimmable and does not declare NativeAOT compatibility.
Klyroo ecosystem
Klyroo is a family of independent .NET libraries that compose. Each one has its own repository, versions and releases.
| Library | Description |
|---|---|
| Klyroo.UI | Accessible Blazor components for the web and .NET MAUI Blazor Hybrid, styled with Tailwind CSS v4 |
| Klyroo.Query | Typed query model, URL state sync, and IQueryable / EF Core execution |
| Klyroo.Table | Data lists with table and card-grid layouts, filters, selection and actions |
| Klyroo.Form | Schema-driven forms, validation and wizards |
| Klyroo.Dashboard | Dashboard controller, filters and Blazor blocks: stats, gauges, charts, tables and feeds |
| Klyroo.Display | Code highlighting, secret and file list components, media player controls and file preview |
| Klyroo.Spreadsheet | Import wizard for CSV, TSV and pasted data, with column and value mapping |
| Klyroo.Agent | Bridge that lets AI agents read and act on Klyroo forms, dashboards and imports |
| Klyroo.Hotkey | Server-side .NET client for Hotkey cloud browsers, human handoffs and signed webhooks |
| Klyroo.Stack | Meta-package, MCP documentation server and dotnet new templates |
Contributing
Contributions are welcome. Read CONTRIBUTING.md before opening a pull request, and follow the code of conduct. Report security issues privately as described in SECURITY.md.
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. net11.0 is compatible. |
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Klyroo.Form.Core:
| Package | Downloads |
|---|---|
|
Klyroo.Stack.Core
Klyroo Core Meta-Package: aggregates all headless, NativeAOT-compatible Core engines of Klyroo (Query, Table, Form, Dashboard, Display, Spreadsheet, Agent) and the KlyrooStackCatalog router. |
|
|
Klyroo.Form.DataAnnotations
Klyroo Form DataAnnotations: builds a Klyroo.Form form from a C# model and its System.ComponentModel.DataAnnotations attributes, and validates IValidatableObject and custom validation attributes at submit. |
|
|
Klyroo.Form
Klyroo Form for Blazor Web & .NET MAUI Hybrid: KlyDynamicFormEngine, KlyDynamicFormPage, KlyFormProvider. |
|
|
Klyroo.Agent
Klyroo Semantic Agent Bridge for Blazor Web & .NET MAUI Hybrid: connects Klyroo.Form, Klyroo.Dashboard, and Klyroo.Spreadsheet to AI agents and WebMCP. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-preview.2 | 42 | 11/29/2026 |
| 0.1.0-preview.1 | 44 | 11/29/2026 |