FormToolData

Trait FormToolData 

Source
pub trait FormToolData:
    Clone
    + Send
    + Sync
    + 'static {
    type Style: FormStyle;
    type Context: Send + Sync + 'static;

    // Required method
    fn build_form(fb: FormBuilder<Self>) -> FormBuilder<Self>;

    // Provided methods
    fn get_form<ServFn, F: Fn(SubmitEvent, RwSignal<Self>) + 'static>(
        self,
        action: ServerAction<ServFn>,
        on_submit: F,
        style: Self::Style,
        context: Self::Context,
    ) -> Form<Self>
       where ServFn: DeserializeOwned + ServerFn<Protocol = Http<PostUrl, Json>> + From<Self> + Clone + Send + Sync + 'static,
             <<ServFn::Client as Client<ServFn::Error>>::Request as ClientReq<ServFn::Error>>::FormData: From<FormData>,
             ServFn::Output: Send + Sync + 'static,
             ServFn::Error: Send + Sync + 'static,
             <ServFn as ServerFn>::Client: Client<<ServFn as ServerFn>::Error> { ... }
    fn get_action_form<ServFn, F: Fn(SubmitEvent, RwSignal<Self>) + 'static>(
        self,
        action: ServerAction<ServFn>,
        on_submit: F,
        style: Self::Style,
        context: Self::Context,
    ) -> Form<Self>
       where ServFn: DeserializeOwned + ServerFn<Protocol = Http<PostUrl, Json>> + From<Self> + Clone + Send + Sync + 'static,
             <<ServFn::Client as Client<ServFn::Error>>::Request as ClientReq<ServFn::Error>>::FormData: From<FormData>,
             ServFn::Output: Send + Sync + 'static,
             ServFn::Error: Send + Sync + 'static,
             <ServFn as ServerFn>::Client: Client<<ServFn as ServerFn>::Error> { ... }
    fn get_plain_form<F: Fn(SubmitEvent, RwSignal<Self>) + 'static>(
        self,
        url: impl ToString,
        on_submit: F,
        style: Self::Style,
        context: Self::Context,
    ) -> Form<Self> { ... }
    fn get_form_controls(
        self,
        style: Self::Style,
        context: Self::Context,
    ) -> Form<Self> { ... }
    fn get_validator(context: Self::Context) -> FormValidator<Self> { ... }
    fn validate(&self, context: Self::Context) -> Result<(), String> { ... }
}
Expand description

A trait allowing a form to be built around its containing data.

This trait defines a function that can be used to build all the data needed to physically lay out a form, and how that data should be parsed and validated.

Required Associated Types§

Source

type Style: FormStyle

The style that this form uses.

Source

type Context: Send + Sync + 'static

The context that this form is rendered in.

This will need to be provided when building a form or a validator. Therefore, you will need to be able to replicate this context on the client for rendering and the server for validating.

Required Methods§

Source

fn build_form(fb: FormBuilder<Self>) -> FormBuilder<Self>

Defines how the form should be laid out and how the data should be parsed and validated.

To construct a From object, use one of the get_form methods.

Uses the given form builder to specify what fields should be present in the form, what properties those fields should have, and how that data should be parsed and checked.

Provided Methods§

Source

fn get_form<ServFn, F: Fn(SubmitEvent, RwSignal<Self>) + 'static>( self, action: ServerAction<ServFn>, on_submit: F, style: Self::Style, context: Self::Context, ) -> Form<Self>
where ServFn: DeserializeOwned + ServerFn<Protocol = Http<PostUrl, Json>> + From<Self> + Clone + Send + Sync + 'static, <<ServFn::Client as Client<ServFn::Error>>::Request as ClientReq<ServFn::Error>>::FormData: From<FormData>, ServFn::Output: Send + Sync + 'static, ServFn::Error: Send + Sync + 'static, <ServFn as ServerFn>::Client: Client<<ServFn as ServerFn>::Error>,

Constructs a Form for this FormToolData type.

This renders the form as a enhanced ActionForm that sends the form data directly by calling the server function.

By doing this, we avoid doing the FromFormData conversion. However, to support Progressive Enhancement, you should name the form elements to work with a plain ActionForm anyway. If progresssive enhancement is not important to you, you may freely use this version.

For the other ways to construct a Form, see:

Source

fn get_action_form<ServFn, F: Fn(SubmitEvent, RwSignal<Self>) + 'static>( self, action: ServerAction<ServFn>, on_submit: F, style: Self::Style, context: Self::Context, ) -> Form<Self>
where ServFn: DeserializeOwned + ServerFn<Protocol = Http<PostUrl, Json>> + From<Self> + Clone + Send + Sync + 'static, <<ServFn::Client as Client<ServFn::Error>>::Request as ClientReq<ServFn::Error>>::FormData: From<FormData>, ServFn::Output: Send + Sync + 'static, ServFn::Error: Send + Sync + 'static, <ServFn as ServerFn>::Client: Client<<ServFn as ServerFn>::Error>,

Constructs a Form for this FormToolData type.

This renders the form as a the ActionForm component.

For the other ways to construct a Form, see:

Source

fn get_plain_form<F: Fn(SubmitEvent, RwSignal<Self>) + 'static>( self, url: impl ToString, on_submit: F, style: Self::Style, context: Self::Context, ) -> Form<Self>

Constructs a Form for this FormToolData type.

This renders the form as a the leptos_router Form component.

For the other ways to construct a Form, see:

Source

fn get_form_controls( self, style: Self::Style, context: Self::Context, ) -> Form<Self>

Constructs a Form for this FormToolData type.

This renders the form without wrapping it in any form html elements. This can be useful if you want to do that yourself, or if you are just using the FormData signal for some non-form purpose.

For the other ways to construct a Form, see:

Source

fn get_validator(context: Self::Context) -> FormValidator<Self>

Gets a FormValidator for this FormToolData.

This doesn’t render the view, but just collects all the validation Functions from building the form. That means it can be called on the Server and no rendering will be done.

However, the code to render the views are not configured out, it simply doesn’t run, so the view needs to compile even on the server.

Source

fn validate(&self, context: Self::Context) -> Result<(), String>

Validates this FormToolData struct.

This is shorthand for creating a validator with get_validator() and then calling validator.validate(&self, context).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§