pub struct Field { /* private fields */ }Expand description
One form field binding a lens to the control editing it, offering only that control’s modifiers so a modifier on the wrong control does not compile.
Field::text(lens!(User.name)).placeholder("Ada Lovelace"); // TextField
Field::text(lens!(User.email)).email().unique();
Field::text(lens!(User.age)); // typed: an `i64` column
Field::text(lens!(Post.body)).multiline(6);
Field::choice(lens!(Post.status)).options(Status::options()); // ChoiceField
Field::choice(lens!(Post.author_id)).relationship::<AuthorResource>();
Field::file(lens!(Doc.path)); // FileField
Field::files(lens!(Doc.attachments)); // FileField over a `Vec<String>`
Field::toggle(lens!(Post.featured)); // CustomFieldOptions belong to a choice: a text field has no options method.
Implementations§
Source§impl Field
impl Field
Sourcepub fn rich_text<M, T>(lens: impl Into<Path<M, T>>) -> RichTextField
pub fn rich_text<M, T>(lens: impl Into<Path<M, T>>) -> RichTextField
A rich text field over a String or Option<String> column, storing HTML its toolbar’s
Tools produce: the server removes anything else from a submission before it parses it.
A record form’s text control becomes one with
TextField::rich_text.
use tablo_core::Field;
Field::rich_text(Post::fields().body()).placeholder("The full story…");Sourcepub fn rich_text_input(name: impl Into<String>) -> RichTextField
pub fn rich_text_input(name: impl Into<String>) -> RichTextField
A rich text field posting name, a key no column binds: a
FormInput field.
Source§impl Field
impl Field
Sourcepub fn text<M, T>(lens: impl Into<Path<M, T>>) -> TextField
pub fn text<M, T>(lens: impl Into<Path<M, T>>) -> TextField
Binds any FormScalar column, storing the type’s own spelling and probing uniqueness
through the lens.
Sourcepub fn choice<M, T>(lens: impl Into<Path<M, T>>) -> ChoiceFieldwhere
M: Model,
pub fn choice<M, T>(lens: impl Into<Path<M, T>>) -> ChoiceFieldwhere
M: Model,
A choice field over any column, with options from options or
relationship.
Sourcepub fn file<M>(lens: impl Into<Path<M, String>>) -> FileFieldwhere
M: Model,
pub fn file<M>(lens: impl Into<Path<M, String>>) -> FileFieldwhere
M: Model,
A file field over a String column holding the uploaded path, rendering no value
attribute.
Sourcepub fn files<M>(lens: impl Into<Path<M, List<String>>>) -> FileFieldwhere
M: Model,
pub fn files<M>(lens: impl Into<Path<M, List<String>>>) -> FileFieldwhere
M: Model,
A file field over a Vec<String> column holding the uploaded paths, in the order the
form lists them: a record form’s #[form(file)] control on a Vec<String>.
The input takes several files at once, which the submission adds after the stored ones,
and each stored file has its own remove checkbox and, with JavaScript, buttons moving it:
the list saves in the order its rows show. A resource’s form reads the paths into key’s
list, starting from the record’s stored list: only a remove checkbox drops a path.
A page handling its own post receives each chosen file’s name under key, each row’s path
under keep_<key> in the order the rows post them, and each removed path under
clear_<key>, and checks them against its record itself.
FileField::max_files bounds the count; the extensions and size apply to each file.
Sourcepub fn toggle<M>(lens: impl Into<Path<M, bool>>) -> CustomFieldwhere
M: Model,
pub fn toggle<M>(lens: impl Into<Path<M, bool>>) -> CustomFieldwhere
M: Model,
A checkbox over a bool column that submits false when unchecked.
Sourcepub fn custom<M, T>(
lens: impl Into<Path<M, T>>,
control: impl Control + 'static,
) -> CustomFieldwhere
M: Model,
T: FormScalar,
pub fn custom<M, T>(
lens: impl Into<Path<M, T>>,
control: impl Control + 'static,
) -> CustomFieldwhere
M: Model,
T: FormScalar,
A field over any FormScalar column, rendered by an app’s Control.
Sourcepub fn repeater<M, T>(lens: impl Into<Path<M, List<T>>>) -> RepeaterField
pub fn repeater<M, T>(lens: impl Into<Path<M, List<T>>>) -> RepeaterField
A row of T’s controls per item of a #[document] list of T, which the browser adds,
removes and moves: a record form’s #[form(repeat)] control.
Each row posts its item’s keys under {key}.{row}.. A resource’s form and an action’s
input read them into key’s rows, and a page handling its own post reads it with
Schema::read; the items then parse with
parse_items. RepeaterField has the rules.
Sourcepub fn text_input<T: FormScalar>(name: impl Into<String>) -> TextField
pub fn text_input<T: FormScalar>(name: impl Into<String>) -> TextField
A text field posting name, a key no column binds: a FormInput
field. T picks the input type, as a column’s type does for Field::text.
Sourcepub fn choice_input(name: impl Into<String>) -> ChoiceField
pub fn choice_input(name: impl Into<String>) -> ChoiceField
A choice field posting name, a key no column binds, with options from
options.
Sourcepub fn toggle_input(name: impl Into<String>) -> CustomField
pub fn toggle_input(name: impl Into<String>) -> CustomField
A checkbox posting name, a key no column binds, that submits false when unchecked.