#[derive(RecordForm)]
{
// Attributes available to this derive:
#[form]
}
Expand description
Derive RecordForm for the typed value a resource’s form writes.
One field per model column the form writes, named and typed like the
model’s field. A scalar (String, a TypedValue type, or an Option of
one) binds the key its control posts; a #[form(embed)] field binds every
key of an EmbeddedForm value and is written whole.
#[derive(tablo_core::RecordForm)]
#[form(model = User)]
pub struct UserForm {
pub name: String,
#[form(blank = "member")]
pub role: String,
#[form(blank = 0)]
pub age: i64,
}The derive also emits UserFormField, one variant per field, which
Posted keys on and RecordForm::fields answers with each variant’s keys.
It emits UserFormControls, one control per field chosen from the field —
a bool is a toggle, #[form(options = T)] a choice over T’s options,
#[form(choice)] a bare choice, #[form(file)] a file field,
#[form(embed)] the embedded value’s schema, and any other field a text
field — with controls() handing them over and RecordForm::schema
arranging one per field in declaration order. RecordForm::table lists a
sortable column per text field, searchable over a String or
Option<String>, an options field by its option’s label, and a toggle as
yes or no. A resource’s ResourceDef defaults its form and table to them;
ResourceDef::form and ResourceDef::table arrange or extend them instead.
§Attributes
#[form(model = User)]on the struct: the model the form writes.#[form(blank = <expr>)]on a scalar: the value an empty submission reads as, overriding the default (Stringanswers""andOption<T>answersNonethrough the type’s own blank, andboolanswersfalsethrough the derive’s default).#[form(options = Status)]: a choice overStatus::options().#[form(choice)]: a bare choice, whose options or relationship the resource’sformmay add.#[form(file)]on aString: a file field.#[form(embed)]on anEmbeddedFormvalue.
A generic struct, a tuple struct, an empty struct, a Deferred<_> field,
blank on an Option or an embedded value, and an unknown key are compile
errors. So are a field the model lacks, a type the model’s field does not
have, and a scalar that is not a FormScalar.
Derive RecordForm for the typed value a resource’s form writes; documented on the tablo-core
re-export.