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§
Sourcetype CustomOptions: Default
type CustomOptions: Default
Custom options for the form field, unique for each field type.
Required Methods§
Sourcefn with_options(
options: FormFieldOptions,
custom_options: Self::CustomOptions,
) -> Selfwhere
Self: Sized,
fn with_options(
options: FormFieldOptions,
custom_options: Self::CustomOptions,
) -> Selfwhere
Self: Sized,
Creates a new form field with the given options.
Sourcefn options(&self) -> &FormFieldOptions
fn options(&self) -> &FormFieldOptions
Returns the generic options for the form field.
Sourcefn set_value(
&mut self,
field: FormFieldValue<'_>,
) -> impl Future<Output = Result<(), FormFieldValueError>> + Send
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§
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.