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§
Required Methods§
Sourcefn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>where
Self: Sized,
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
Sourcefn to_field_value(&self) -> String
fn to_field_value(&self) -> String
Returns self as a value that can be set with FormField::set_value.
Provided Methods§
Sourcefn new_field(
options: FormFieldOptions,
custom_options: <Self::Type as FormField>::CustomOptions,
) -> Self::Type
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
impl AsFormField for Weekday
type Type = SelectField<Weekday>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for bool
Implementation of AsFormField for bool.
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.
type Type = BoolField
fn new_field( options: FormFieldOptions, custom_options: <Self::Type as FormField>::CustomOptions, ) -> Self::Type
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for f32
impl AsFormField for f32
type Type = FloatField<f32>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for f64
impl AsFormField for f64
type Type = FloatField<f64>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for i8
impl AsFormField for i8
type Type = IntegerField<i8>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for i16
impl AsFormField for i16
type Type = IntegerField<i16>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for i32
impl AsFormField for i32
type Type = IntegerField<i32>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for i64
impl AsFormField for i64
type Type = IntegerField<i64>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for i128
impl AsFormField for i128
type Type = IntegerField<i128>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for isize
impl AsFormField for isize
type Type = IntegerField<isize>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for u8
impl AsFormField for u8
type Type = IntegerField<u8>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for u16
impl AsFormField for u16
type Type = IntegerField<u16>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for u32
impl AsFormField for u32
type Type = IntegerField<u32>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for u64
impl AsFormField for u64
type Type = IntegerField<u64>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for u128
impl AsFormField for u128
type Type = IntegerField<u128>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for usize
impl AsFormField for usize
type Type = IntegerField<usize>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for String
impl AsFormField for String
type Type = StringField
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for DateTime<FixedOffset>
impl AsFormField for DateTime<FixedOffset>
type Type = DateTimeWithTimezoneField
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>where
Self: Sized,
fn to_field_value(&self) -> String
Source§impl AsFormField for NaiveDate
impl AsFormField for NaiveDate
type Type = DateField
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>where
Self: Sized,
fn to_field_value(&self) -> String
Source§impl AsFormField for NaiveDateTime
impl AsFormField for NaiveDateTime
type Type = DateTimeField
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>where
Self: Sized,
fn to_field_value(&self) -> String
Source§impl AsFormField for NaiveTime
impl AsFormField for NaiveTime
type Type = TimeField
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>where
Self: Sized,
fn to_field_value(&self) -> String
Source§impl AsFormField for WeekdaySet
impl AsFormField for WeekdaySet
type Type = SelectMultipleField<Weekday>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for NonZeroI8
impl AsFormField for NonZeroI8
type Type = IntegerField<NonZero<i8>>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for NonZeroI16
impl AsFormField for NonZeroI16
type Type = IntegerField<NonZero<i16>>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for NonZeroI32
impl AsFormField for NonZeroI32
type Type = IntegerField<NonZero<i32>>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for NonZeroI64
impl AsFormField for NonZeroI64
type Type = IntegerField<NonZero<i64>>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for NonZeroI128
impl AsFormField for NonZeroI128
type Type = IntegerField<NonZero<i128>>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for NonZeroIsize
impl AsFormField for NonZeroIsize
type Type = IntegerField<NonZero<isize>>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for NonZeroU8
impl AsFormField for NonZeroU8
type Type = IntegerField<NonZero<u8>>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for NonZeroU16
impl AsFormField for NonZeroU16
type Type = IntegerField<NonZero<u16>>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for NonZeroU32
impl AsFormField for NonZeroU32
type Type = IntegerField<NonZero<u32>>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for NonZeroU64
impl AsFormField for NonZeroU64
type Type = IntegerField<NonZero<u64>>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for NonZeroU128
impl AsFormField for NonZeroU128
type Type = IntegerField<NonZero<u128>>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl AsFormField for NonZeroUsize
impl AsFormField for NonZeroUsize
type Type = IntegerField<NonZero<usize>>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl<T: SelectChoice + Eq + Hash + Send> AsFormField for IndexSet<T>
impl<T: SelectChoice + Eq + Hash + Send> AsFormField for IndexSet<T>
type Type = SelectMultipleField<T>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl<T: SelectChoice + Eq + Hash + Send, S: BuildHasher + Default> AsFormField for HashSet<T, S>
impl<T: SelectChoice + Eq + Hash + Send, S: BuildHasher + Default> AsFormField for HashSet<T, S>
type Type = SelectMultipleField<T>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl<T: SelectChoice + Send> AsFormField for LinkedList<T>
impl<T: SelectChoice + Send> AsFormField for LinkedList<T>
type Type = SelectMultipleField<T>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl<T: SelectChoice + Send> AsFormField for VecDeque<T>
impl<T: SelectChoice + Send> AsFormField for VecDeque<T>
type Type = SelectMultipleField<T>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl<T: SelectChoice + Send> AsFormField for Vec<T>
impl<T: SelectChoice + Send> AsFormField for Vec<T>
type Type = SelectMultipleField<T>
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Source§impl<T: AsFormField> AsFormField for Option<T>
impl<T: AsFormField> AsFormField for Option<T>
type Type = <T as AsFormField>::Type
fn new_field( options: FormFieldOptions, custom_options: <Self::Type as FormField>::CustomOptions, ) -> Self::Type
fn clean_value(field: &Self::Type) -> Result<Self, FormFieldValidationError>
fn to_field_value(&self) -> String
Implementors§
Source§impl AsFormField for PasswordHash
impl AsFormField for PasswordHash
type Type = PasswordField
Source§impl AsFormField for Email
impl AsFormField for Email
type Type = EmailField
Source§impl AsFormField for Password
impl AsFormField for Password
type Type = PasswordField
Source§impl AsFormField for InMemoryUploadedFile
impl AsFormField for InMemoryUploadedFile
Source§impl<T> AsFormField for ForeignKey<T>
Available on crate feature db only.
impl<T> AsFormField for ForeignKey<T>
db only.type Type = <<T as Model>::PrimaryKey as AsFormField>::Type
Source§impl<T: AsFormField> AsFormField for Auto<T>
Available on crate feature db only.
impl<T: AsFormField> AsFormField for Auto<T>
db only.type Type = <T as AsFormField>::Type
Source§impl<const LEN: u32> AsFormField for LimitedString<LEN>
Available on crate feature db only.
impl<const LEN: u32> AsFormField for LimitedString<LEN>
db only.