Actively developed · Breaking changes are still expected.

Slint Kit Documentation

Search the documentation

    ↑ ↓ to browse · Enter to open · Escape to close

    Forms

    Form for Slint

    KitForm · Slint Kit 0.9.0

    Form composition with shared validation, first-invalid focus and guarded submission.

    The still preview and demo follow the documentation theme. You can change it before or during the demo.

    Form composition with shared validation, first-invalid focus and guarded submission.
    Slint components with their built-in Tailwind appearance, rendered in the browser.

    This preview runs the actual Slint components and their Rust code compiled to WebAssembly. Slint draws the interface in the browser; the downloadable project compiles the same example into a native application for your platform.

    Try the component

    Download the complete project, extract it and run cargo run --locked in its folder. To add this component to an application, follow Project setup, then copy the two files below.

    The kit supplies the component's behavior and styles; Rust callbacks connect its typed values to your application.

    Complete name, email, date and consent, then Register: Rust receives one typed Registration. Invalid values report together; Reset restores each field. Its single schema declaration and business code fit in fifteen Rust lines.

    ui/app.slint

    // SPDX-License-Identifier: GPL-3.0-or-later
    import { InterFont } from "@kit-fonts/inter.slint";
    import { KitForm, FormFieldView, KitTextField, KitEmailField, KitDateField, KitCheckbox, KitFieldError, CheckState, KitButton, KitFormErrorSummary, KitTheme, KitThemeContext, FieldCommit, KitValidityState, FormErrorRow, CommitPolicy, ValidationPresentation, FieldAccess, FocusRequest } from "@kit";
    export enum RegistrationField { name, email, birth, consent }
    export component App inherits Window {
        in-out property <KitTheme> theme: KitThemeContext.current;
        default-font-family: InterFont.family;
        background: root.theme.canvas;
        title: "Registration"; preferred-width: 560px; preferred-height: 950px;
        in property <bool> valid;
        in property <bool> dirty;
        in property <bool> submitting;
        in property <[FormErrorRow]> errors;
        in property <string> result;
        callback validate-form() -> bool;
        callback send-form(); callback reset-form(); callback edited();
        callback field-edited(RegistrationField);
        callback focus-error(FocusRequest);
        callback field-committed(FieldCommit);
        out property <bool> birth-focused: birth.has-focus;
        public function select-email() { email.select-all(); }
        public function undo-email() { email.undo(); }
        public function focus-form() { form.take-focus(); }
        in-out property <string> name-text: "Ada";
        in property <string> name-error;
        out property <FieldCommit> name-candidate: {value: {present: name.value != "", text: name.value}, constraints: name.constraints};
        out property <FormFieldView> name-field: {will-validate: name.will-validate, validity: name.validity, dirty: name.dirty, message: name.validation-message, target: {present: true, token: 1, generation: 1, request: 1}};
        public function report-name() -> bool { return name.report-validity(); }
        public function focus-name() -> bool { name.take-focus(); return name.access != FieldAccess.disabled; }
        public function reset-name() { name.reset-field(); }
        in-out property <string> email-text: "hello@example.com";
        in property <string> email-error;
        out property <FieldCommit> email-candidate: {value: {present: email.value != "", text: email.value}, constraints: email.constraints};
        out property <FormFieldView> email-field: {will-validate: email.will-validate, validity: email.validity, dirty: email.dirty, message: email.validation-message, target: {present: true, token: 2, generation: 1, request: 1}};
        public function report-email() -> bool { return email.report-validity(); }
        public function focus-email() -> bool { email.take-focus(); return email.access != FieldAccess.disabled; }
        public function reset-email() { email.reset-field(); }
        in-out property <string> birth-text: "2026-10-19";
        in property <string> birth-error;
        out property <FieldCommit> birth-candidate: {value: {present: birth.value != "", text: birth.value}, constraints: birth.constraints};
        out property <FormFieldView> birth-field: {will-validate: birth.will-validate, validity: birth.validity, dirty: birth.dirty, message: birth.validation-message, target: {present: true, token: 3, generation: 1, request: 1}};
        public function report-birth() -> bool { return birth.report-validity(); }
        public function focus-birth() -> bool { birth.take-focus(); return birth.access != FieldAccess.disabled; }
        public function reset-birth() { birth.reset-field(); }
        out property <KitValidityState> email-validity: email.validity;
        out property <bool> email-will-validate: email.will-validate;
        out property <bool> email-dirty: email.dirty;
        out property <string> email-message: email.validation-message;
        out property <FieldCommit> candidate: root.email-candidate;
        in-out property <CheckState> consent-state: CheckState.checked;
        in-out property <bool> consent-dirty;
        in property <string> consent-error;
        out property <FormFieldView> consent-field: {will-validate: consent.will-validate, validity: consent.validity, dirty: root.consent-dirty, message: consent.validation-message, target: {present: true, token: 4, generation: 1, request: 1}};
        public function report-consent() -> bool { return consent.report-validity(); }
        public function focus-consent() -> bool { consent.take-focus(); return consent.access != FieldAccess.disabled; }
        public function reset-consent() { root.consent-state = CheckState.checked; root.consent-dirty = false; consent.reset-validation(); }
        VerticalLayout { padding: 24px; alignment: start;
            form := KitForm {
                theme: root.theme; accessible-name: "Registration form";
                valid: root.valid; dirty: root.dirty; submitting: root.submitting; errors: root.errors;
                validation-requested => { return root.validate-form(); }
                submit-requested => { root.send-form(); }
                reset-requested => { root.reset-form(); }
                KitFormErrorSummary { theme: root.theme; errors: root.errors; error-activated(target) => { root.focus-error(target); } }
                name := KitTextField {
                    theme: root.theme; label: "Name"; required: true;
                    default-value: "Ada"; text <=> root.name-text;
                    commit-policy: CommitPolicy.on-submit;
                    error: root.name-error; validation: root.name-error != "" ? ValidationPresentation.invalid : ValidationPresentation.pristine;
                    edited(value) => { root.field-edited(RegistrationField.name); root.edited(); }
                }
                email := KitEmailField { pattern: "[^@]+@[^@]+[.][^@]+"; pattern-message: "Use an email domain with a suffix, such as acme.tld.";
                    theme: root.theme; label: "Email"; required: true;
                    default-value: "hello@example.com"; text <=> root.email-text;
                    commit-policy: CommitPolicy.on-submit;
                    error: root.email-error; validation: root.email-error != "" ? ValidationPresentation.invalid : ValidationPresentation.pristine;
                    edited(value) => { root.field-edited(RegistrationField.email); root.edited(); }
                    committed(value) => { root.field-committed(value); }
                }
                birth := KitDateField {
                    theme: root.theme; label: "Birth date"; required: true;
                    default-value: "2026-10-19"; text <=> root.birth-text;
                    commit-policy: CommitPolicy.on-submit;
                    error: root.birth-error; validation: root.birth-error != "" ? ValidationPresentation.invalid : ValidationPresentation.pristine;
                    edited(value) => { root.field-edited(RegistrationField.birth); root.edited(); }
                }
                consent := KitCheckbox {
                    theme: root.theme; label: "Accept the terms"; required: true; state <=> root.consent-state;
                    toggled(value) => { root.consent-dirty = true; root.field-edited(RegistrationField.consent); }
                }
                if root.consent-error != "" || consent.error-visible: KitFieldError { theme: root.theme; text: root.consent-error != "" ? root.consent-error : consent.validation-message; }
                HorizontalLayout {
                    alignment: start;
                    KitButton { theme: root.theme; text: "Register"; disabled: root.submitting; activated => { form.submit(); } }
                    KitButton { theme: root.theme; text: "Reset"; activated => { form.reset(); } }
                }
                Text { text: root.result != "" ? "Registered " + root.result : "Edit the fields, then Register or Reset."; color: root.theme.text-primary; wrap: word-wrap; }
            }
        }
    }
    
    

    src/main.rs

    // SPDX-License-Identifier: GPL-3.0-or-later
    use slint::ComponentHandle;
    slint::include_modules!();
    slint_kit::form_schema!(Registration, App, RegistrationField, {
        name: required(slint_kit::TextValue, slint_kit::FieldSpec::text(), "Check name"),
        email: required(slint_kit::EmailAddress, slint_kit::FieldSpec::email(), "Check email"),
        birth: required(slint_kit::CivilDate, slint_kit::FieldSpec::date(), "Check birth"),
        consent: checked,
    });
    fn main() -> Result<(), slint::PlatformError> {
        let app = App::new()?;
        slint_kit::install(&app);
        Registration::on_submit(&app, |app, data| app.set_result(data.email.as_str().into()));
        app.run()
    }
    
    

    Files: Cargo.toml · build.rs · ui/app.slint · src/main.rs

    Compose fields and actions in KitForm. Declare the typed record once with form_schema!(Record, Window, FieldKeys, { field: required(Type, FieldSpec, message), consent: checked }). The macro generates Rust ports and global form callbacks from the public window naming convention; missing ports, incompatible codecs and unregistered field-key variants fail compilation. The complete four-field starter is fifteen Rust lines including schema and business logic, with no helper module. Record::on_submit admits a typed record and completes synchronous success; Record::bind returns TypedFormBinding for asynchronous tickets and server errors. Advanced compositions can declare FormFieldPorts once through bind_required/bind_checked, combine them with zip/map and call with_schema; no caller validation loop or duplicate parser is needed.

    The Rust adapter reports every registered field before focusing the first invalid one exactly once, aggregates HTML validity, rejects duplicate keys and concurrent submissions, and drops stale responses after reset. finish(ticket, errors) publishes server errors; reset restores every registered field. Call refresh() after field edits or model changes. KitForm exposes report-validity(), submit(), reset(), valid, dirty, submitting and errors. Submission is blocked until validation is wired; implicit Enter submission excludes multiline fields and active IME preedit. Native accessibility role is form; set accessible-name. Implicit Enter is deferred until the native editor accepts it; custom handled shortcuts and auxiliary editor opt-outs do not submit the form. Set form-no-validate for an explicit UI validation opt-out and call FormBinding::submit_without_validation on that corresponding Rust path; both retain busy/window guards. Ordinary Rust submit always enforces validation. Raw custom TextInput editors wire accepted to form.submit() explicitly. register_focusable/register_view focus callbacks return whether focus was requested. If an invalid read-only file cannot take focus, try the next invalid field; set_focus_fallback can focus the form when none admits it. finish routes messages to each registered field and the summary without replacing drafts; field_edited clears only that key’s server error. Unknown error keys remain in the summary without a fabricated focus target. Checkbox, switch and shared radio/toggle Enter submit the enclosing form; Space still changes choices, while selectors, tag entry, table editors and host-consumed shortcuts keep Enter.

    Control states

    valid aggregates the registered HTML snapshots, dirty reflects edits, and submitting follows the active FormCoordinator ticket. Reset invalidates pending responses. Codecs and domain payloads still pass through FieldSpec::accept at the Rust boundary.

    Control accessibility

    The container exposes the native form role and accessible-name. Registered field focus callbacks keep the first-invalid focus order independent of visual row indices. Render errors with KitFormErrorSummary; each message retains its FocusRequest target. Native editor/IME processing owns Enter before implicit submission.

    Visual composition

    The file below describes the captured scene. For controller-driven components, it shows the displayed state without supplying the Rust wiring. Create a project.

    Show the screenshot source
    Form composition with shared validation, first-invalid focus and guarded submission.
    Browser capture of the same Slint example, femtovg renderer.
    // SPDX-License-Identifier: GPL-3.0-or-later
    import { KitForm, KitTextField, KitEmailField, KitDateField, KitCheckbox, CheckState, KitButton, KitFieldError, KitTheme, KitThemes } from "@kit";
    export component Example inherits Window {
        in-out property <KitTheme> theme: KitThemes.light;
        background: root.theme.canvas;
        preferred-width: 520px; preferred-height: 680px;
        callback submit-requested();
        VerticalLayout { padding: 24px;
            form := KitForm {
                theme: root.theme;
                accessible-name: "Registration";
                validation-requested => {
                    let name-valid = name.report-validity();
                    let email-valid = email.report-validity();
                    let birth-valid = birth.report-validity();
                    let consent-valid = consent.report-validity();
                    if (!name-valid) { name.focus-if-invalid(); }
                    else if (!email-valid) { email.focus-if-invalid(); }
                    else if (!birth-valid) { birth.focus-if-invalid(); }
                    else if (!consent-valid) { consent.focus-if-invalid(); }
                    return name-valid && email-valid && birth-valid && consent-valid;
                }
                submit-requested => { root.submit-requested(); }
                reset-requested => {
                    name.reset-field(); email.reset-field(); birth.reset-field();
                    consent.state = CheckState.unchecked; consent.reset-validation();
                }
                name := KitTextField { theme: root.theme; label: "Name"; required: true; }
                email := KitEmailField { pattern: "[^@]+@[^@]+[.][^@]+"; pattern-message: "Use an email domain with a suffix, such as acme.tld."; theme: root.theme; label: "Email"; required: true; }
                birth := KitDateField { theme: root.theme; label: "Birth date"; required: true; }
                consent := KitCheckbox { theme: root.theme; label: "Accept the terms"; required: true; }
                if consent.error-visible: KitFieldError { theme: root.theme; text: consent.validation-message; }
                HorizontalLayout {
                    alignment: start;
                    KitButton { theme: root.theme; text: "Register"; activated => { form.submit(); } }
                    KitButton { theme: root.theme; text: "Reset"; activated => { form.reset(); } }
                }
            }
        }
    }
    
    

    Download this example

    Public API

    Inherits FocusScope.

    Properties

    The "Default" column repeats the initializer declared in the source; "—" is the zero value of the type, and a composite expression points to the source.

    Name Type Direction Default
    modal-layer int in —
    theme KitTheme in KitThemeContext.current
    accessible-name string in —
    valid bool in —
    dirty bool in —
    submitting bool in —
    errors [FormErrorRow] in —
    implicit-submit bool in true
    form-no-validate bool in —

    Property details

    Effect, default, states and constraints of the central properties, with a snippet that uses public mechanisms. Inherited properties carry the explanation of the component that declares them. The complete typed example and the Forms guide wire these properties end to end.

    modal-layer int · in

    The modal layer this component belongs to; 0 is the window. While a KitDialogSurface or KitDrawer with a positive modal-layer is open and topmost, the form is inert: its keyboard scope takes no focus and ignores keys, so Enter no longer submits it. The fields you place inside keep their own modal-layer. Give a component placed inside a modal that modal’s layer number.

    Default
    0 (window).
    KitForm {
        modal-layer: 1;
    }

    accessible-name string · in

    Names the accessible form container. Choose a name that distinguishes this form from other forms in the window.

    valid bool · in

    Publish FormProjection.valid here to expose the current registered HTML validity to actions. Submission still goes through validation-requested.

    dirty bool · in

    Publish FormProjection.dirty here; it reflects whether any registered snapshot reports edits.

    submitting bool · in

    Publish FormProjection.submitting here. While true, submit() and implicit Enter reject a second request.

    errors [FormErrorRow] · in

    Publish FormProjection.errors and bind a KitFormErrorSummary in the form content to the same model. Each row retains its FocusRequest.

    implicit-submit bool · in

    Plain Enter from participating single-line kit editors submits after native acceptance. Turn this off when the form has another Enter policy.

    form-no-validate bool · in

    Explicitly bypass the UI field-validation gate while retaining the submitting guard. Pair the corresponding Rust route with FormBinding::submit_without_validation.

    Types and variants

    Type Declaration
    struct FocusRequest present: bool, token: int, generation: int, request: int
    struct FormErrorRow target: FocusRequest, message: string

    Callbacks

    Functions

    See also