Skip to main content

FormInput

Trait FormInput 

Source
pub trait FormInput:
    Sized
    + Send
    + Sync
    + 'static {
    // Required methods
    fn schema() -> Schema;
    fn parse(cx: &Cx, values: &FormValues) -> Result<Self, Vec<FieldError>>;
    fn write(&self, out: &mut FormValues);
}
Expand description

A typed value a form posts under its own keys, which no column binds: what an Action asks for before it runs, what a sign-up reads, one item of a repeater.

Derive it with FormInput on a struct of form scalars, or name () for a value that asks for nothing.

An action with input asks for it before it runs: its button opens the input form in a dialog over the page, and its submit runs the action with the parsed value. A refused value renders the form as a page with the field’s error, and writes nothing.

A repeater stores its items in a #[document] list, so an item is also a toasty::Embed struct. Each row posts the item’s keys under its own prefix, and write fills a stored item’s row on the edit page.

Required Methods§

Source

fn schema() -> Schema

The value’s controls, each posting its own key. An empty schema asks for nothing: an action runs on its button.

Source

fn parse(cx: &Cx, values: &FormValues) -> Result<Self, Vec<FieldError>>

Parse a submission of schema’s keys.

§Errors

Every key that failed, each once.

Source

fn write(&self, out: &mut FormValues)

Write the value’s keys as its form posts them: a repeater fills a stored item’s row from them, and its detail-page column reads them. A password writes nothing, as it never renders back into a form. Nothing writes an action’s input or a sign-up, so a type used only there writes nothing too.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl FormInput for ()

No input: an action runs on its button.

Source§

fn schema() -> Schema

Source§

fn parse(_cx: &Cx, _values: &FormValues) -> Result<Self, Vec<FieldError>>

Source§

fn write(&self, _out: &mut FormValues)

Implementors§