FormField

Trait FormField 

Source
pub trait FormField: Display {
    type CustomOptions: Default;

    // Required methods
    fn with_options(
        options: FormFieldOptions,
        custom_options: Self::CustomOptions,
    ) -> Self
       where Self: Sized;
    fn options(&self) -> &FormFieldOptions;
    fn value(&self) -> Option<&str>;
    fn set_value(
        &mut self,
        field: FormFieldValue<'_>,
    ) -> impl Future<Output = Result<(), FormFieldValueError>> + Send;

    // Provided methods
    fn id(&self) -> &str { ... }
    fn name(&self) -> &str { ... }
}
Expand description

A form field.

This trait is used to define a type of field that can be used in a form. It is used to render the field in an HTML form, set the value of the field, and validate it. Typically, the implementors of this trait are used indirectly through the Form trait and field types that implement AsFormField.

Required Associated Types§

Source

type CustomOptions: Default

Custom options for the form field, unique for each field type.

Required Methods§

Source

fn with_options( options: FormFieldOptions, custom_options: Self::CustomOptions, ) -> Self
where Self: Sized,

Creates a new form field with the given options.

Source

fn options(&self) -> &FormFieldOptions

Returns the generic options for the form field.

Source

fn value(&self) -> Option<&str>

Returns the string value of the form field.

Source

fn set_value( &mut self, field: FormFieldValue<'_>, ) -> impl Future<Output = Result<(), FormFieldValueError>> + Send

Sets the value of the form field.

This method should convert the value to the appropriate type for the field, such as a number for a number field.

Note that this method might be called multiple times. This will happen when the field has appeared in the form data multiple times, such as in the case of a <select multiple> HTML element. If the field does not support storing multiple values, it should overwrite the previous value.

Provided Methods§

Source

fn id(&self) -> &str

Returns the ID of the form field.

Source

fn name(&self) -> &str

Returns the display name of the form field.

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§