Skip to main content

Module form

Module form 

Source
Expand description

Record forms: the typed value a form submission parses into, and the write that stores it.

Declares one RecordForm struct with one field per written model column. Completes unposted keys from the stored record and writes only named fields plus model defaults.

#[derive(Debug, Clone, toasty::Model)]
struct User {
    #[key]
    #[auto]
    id: uuid::Uuid,
    name: String,
    age: i64,
}

#[derive(tablo_core::RecordForm)]
#[form(model = User)]
struct UserForm {
    name: String,
    #[form(blank = 0)]
    age: i64,
}

// A column type toasty stores but the form edge cannot spell.
#[derive(Debug, Clone, toasty::Model)]
struct Tagged {
    #[key]
    #[auto]
    id: uuid::Uuid,
    tags: Vec<String>,
}

§Compile-time refusals

A field the model does not have:

ⓘ
#[derive(tablo_core::RecordForm)]
#[form(model = User)]
struct UserForm {
    nickname: String,
}

A type the model’s field does not have:

ⓘ
#[derive(tablo_core::RecordForm)]
#[form(model = User)]
struct UserForm {
    age: i32,
}

A scalar type the form edge cannot spell:

ⓘ
#[derive(Debug, Clone, toasty::Model)]
struct Tagged {
    #[key]
    #[auto]
    id: uuid::Uuid,
    tags: Vec<String>,
}

#[derive(tablo_core::RecordForm)]
#[form(model = Tagged)]
struct TaggedForm {
    tags: Vec<String>,
}

embed on a type that is not an EmbeddedForm:

ⓘ
#[derive(tablo_core::RecordForm)]
#[form(model = User)]
struct UserForm {
    #[form(embed)]
    name: String,
}

Structs§

FieldError
One key a submission was refused under, with the sentence the form renders beneath it.
FieldErrors
A refused submission, keyed by the form key each error renders under.
FormField
One record-form field and the form keys it binds.
NoForm
The record form of a resource with no create or edit page.
Posted
An edit submission: the parsed form, and the fields the submission named.

Enums§

FieldErrorKind
Why a key failed to parse.

Traits§

FormScalar
A type one form key reads and writes: String, every TypedValue type, and an Option of either.
RecordForm
The typed value a resource’s form submission parses into.

Functions§

parse_scalar
Read one scalar from a completed submission.