pub struct FormField { /* private fields */ }Expand description
Describes a field to include in a form.
Each field has an ID for retrieval, a label for display, and a kind that determines the widget type and behavior.
Implementations§
Source§impl FormField
impl FormField
Sourcepub fn text(id: impl Into<String>, label: impl Into<String>) -> Self
pub fn text(id: impl Into<String>, label: impl Into<String>) -> Self
Creates a text input field.
§Example
use envision::component::FormField;
let field = FormField::text("email", "Email Address");
assert_eq!(field.id(), "email");
assert_eq!(field.label(), "Email Address");Sourcepub fn text_with_placeholder(
id: impl Into<String>,
label: impl Into<String>,
placeholder: impl Into<String>,
) -> Self
pub fn text_with_placeholder( id: impl Into<String>, label: impl Into<String>, placeholder: impl Into<String>, ) -> Self
Creates a text input field with placeholder text.
§Example
use envision::component::{FormField, FormFieldKind};
let field = FormField::text_with_placeholder("email", "Email", "user@example.com");
assert_eq!(field.id(), "email");
assert!(matches!(field.kind(), FormFieldKind::TextWithPlaceholder(_)));Sourcepub fn checkbox(id: impl Into<String>, label: impl Into<String>) -> Self
pub fn checkbox(id: impl Into<String>, label: impl Into<String>) -> Self
Creates a checkbox field.
§Example
use envision::component::FormField;
let field = FormField::checkbox("agree", "I agree");
assert_eq!(field.id(), "agree");Sourcepub fn select<S: Into<String>>(
id: impl Into<String>,
label: impl Into<String>,
options: Vec<S>,
) -> Self
pub fn select<S: Into<String>>( id: impl Into<String>, label: impl Into<String>, options: Vec<S>, ) -> Self
Creates a select dropdown field.
§Example
use envision::component::{FormField, FormFieldKind};
let field = FormField::select("color", "Favorite Color", vec!["Red", "Green", "Blue"]);
assert_eq!(field.id(), "color");
assert!(matches!(field.kind(), FormFieldKind::Select(_)));Sourcepub fn id(&self) -> &str
pub fn id(&self) -> &str
Returns the field ID.
§Example
use envision::component::FormField;
let field = FormField::text("username", "Username");
assert_eq!(field.id(), "username");Sourcepub fn label(&self) -> &str
pub fn label(&self) -> &str
Returns the field label.
§Example
use envision::component::FormField;
let field = FormField::text("name", "Full Name");
assert_eq!(field.label(), "Full Name");Sourcepub fn kind(&self) -> &FormFieldKind
pub fn kind(&self) -> &FormFieldKind
Returns the field kind.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for FormField
impl<'de> Deserialize<'de> for FormField
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for FormField
Auto Trait Implementations§
impl Freeze for FormField
impl RefUnwindSafe for FormField
impl Send for FormField
impl Sync for FormField
impl Unpin for FormField
impl UnsafeUnpin for FormField
impl UnwindSafe for FormField
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more