AsFormField

Trait AsFormField 

Source
pub trait AsFormField {
    type Type: FormField;

    // Required methods
    fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
       where Self: Sized;
    fn to_field_value(&self) -> String;

    // Provided method
    fn new_field(
        options: FormFieldOptions,
        custom_options: <Self::Type as FormField>::CustomOptions,
    ) -> Self::Type { ... }
}
Expand description

A trait for types that can be used as form fields.

This trait uses FormField to define a type that can be used as a form field. It provides a way to clean the value of the field, which is used to validate the field’s value before converting to the final type.

Required Associated Types§

Source

type Type: FormField

The form field type associated with the field.

Required Methods§

Source

fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
where Self: Sized,

Validates the value of the field and converts it to the final type. This method should return an error if the value is invalid.

§Errors

Returns an error if the value fails to validate or convert to the final type

Source

fn to_field_value(&self) -> String

Returns self as a value that can be set with FormField::set_value.

Provided Methods§

Source

fn new_field( options: FormFieldOptions, custom_options: <Self::Type as FormField>::CustomOptions, ) -> Self::Type

Creates a new form field with the given options and custom options.

This method is used to create a new instance of the form field with the given options and custom options. The options are used to set the properties of the field, such as the ID and whether the field is required.

The custom options are unique to each field type and are used to set additional properties of the 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.

Implementations on Foreign Types§

Source§

impl AsFormField for Weekday

Source§

impl AsFormField for bool

Implementation of AsFormField for bool.

This implementation converts the string values “true”, “on”, and “1” to true, and “false”, “off”, and “0” to false. It returns an error if the value is not one of these strings. If the field is required to be true by the field’s options, it will return an error if the value is false.

Source§

type Type = BoolField

Source§

fn new_field( options: FormFieldOptions, custom_options: <Self::Type as FormField>::CustomOptions, ) -> Self::Type

Source§

fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>

Source§

fn to_field_value(&self) -> String

Source§

impl AsFormField for f32

Source§

impl AsFormField for f64

Source§

impl AsFormField for i8

Source§

impl AsFormField for i16

Source§

impl AsFormField for i32

Source§

impl AsFormField for i64

Source§

impl AsFormField for i128

Source§

impl AsFormField for isize

Source§

impl AsFormField for u8

Source§

impl AsFormField for u16

Source§

impl AsFormField for u32

Source§

impl AsFormField for u64

Source§

impl AsFormField for u128

Source§

impl AsFormField for usize

Source§

impl AsFormField for String

Source§

impl AsFormField for DateTime<FixedOffset>

Source§

impl AsFormField for NaiveDate

Source§

impl AsFormField for NaiveDateTime

Source§

impl AsFormField for NaiveTime

Source§

impl AsFormField for WeekdaySet

Source§

impl AsFormField for NonZeroI8

Source§

impl AsFormField for NonZeroI16

Source§

impl AsFormField for NonZeroI32

Source§

impl AsFormField for NonZeroI64

Source§

impl AsFormField for NonZeroI128

Source§

impl AsFormField for NonZeroIsize

Source§

impl AsFormField for NonZeroU8

Source§

impl AsFormField for NonZeroU16

Source§

impl AsFormField for NonZeroU32

Source§

impl AsFormField for NonZeroU64

Source§

impl AsFormField for NonZeroU128

Source§

impl AsFormField for NonZeroUsize

Source§

impl<T: SelectChoice + Eq + Hash + Send> AsFormField for IndexSet<T>

Source§

impl<T: SelectChoice + Eq + Hash + Send, S: BuildHasher + Default> AsFormField for HashSet<T, S>

Source§

impl<T: SelectChoice + Send> AsFormField for LinkedList<T>

Source§

impl<T: SelectChoice + Send> AsFormField for VecDeque<T>

Source§

impl<T: SelectChoice + Send> AsFormField for Vec<T>

Source§

impl<T: AsFormField> AsFormField for Option<T>

Source§

type Type = <T as AsFormField>::Type

Source§

fn new_field( options: FormFieldOptions, custom_options: <Self::Type as FormField>::CustomOptions, ) -> Self::Type

Source§

fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>

Source§

fn to_field_value(&self) -> String

Implementors§

Source§

impl AsFormField for PasswordHash

Source§

impl AsFormField for Email

Source§

impl AsFormField for Password

Source§

impl AsFormField for Url

Source§

impl AsFormField for InMemoryUploadedFile

Source§

impl<T> AsFormField for ForeignKey<T>
where T: Model, <T as Model>::PrimaryKey: AsFormField,

Available on crate feature db only.
Source§

impl<T: AsFormField> AsFormField for Auto<T>

Available on crate feature db only.
Source§

impl<const LEN: u32> AsFormField for LimitedString<LEN>

Available on crate feature db only.