pub struct FormField<V> { /* private fields */ }Expand description
A labeled form field with a hint and validation messages.
Errors appear once the value is non-empty or the form was submitted
(see FormField::show_errors), so empty forms do not start out red.
use ravenrs_reactive::State;
use ravenrs_widgets::{FormField, TextField, Ui, validate};
let email = State::new("raven@".to_string());
let field = FormField::new("Email", TextField::new(email.binding()))
.hint("We never share it.")
.validate(email.binding(), validate::email);
assert!(field.error().is_some());
email.set("raven@example.com".into());
assert_eq!(field.error(), None);
let mut ui = Ui::new(field, ravenrs_style::Theme::raven_dark());
ui.update();Implementations§
Source§impl<V: View> FormField<V>
impl<V: View> FormField<V>
Sourcepub fn new(label: impl Into<String>, content: V) -> Self
pub fn new(label: impl Into<String>, content: V) -> Self
A field with this label above content.
Sourcepub fn accessible_name(self, name: impl Into<String>) -> Self
pub fn accessible_name(self, name: impl Into<String>) -> Self
What screen readers call the control, instead of the label: for a label that only makes sense next to what is around it.
Sourcepub fn accessible_description(self, text: impl Into<String>) -> Self
pub fn accessible_description(self, text: impl Into<String>) -> Self
What screen readers say after its name, instead of the hint. An error or a note still comes first.
Sourcepub fn required(self) -> Self
pub fn required(self) -> Self
Marks the label with * and adds the validate::required rule (for the value set by FormField::validate).
Sourcepub fn error_text(self, error: Option<String>) -> Self
pub fn error_text(self, error: Option<String>) -> Self
What is wrong, as something else found out, such as rules that read a database.
Sourcepub fn label_ink(self, ink: Semantic) -> Self
pub fn label_ink(self, ink: Semantic) -> Self
The color of its label, instead of the usual one.
Sourcepub fn tint(self, fill: Semantic) -> Self
pub fn tint(self, fill: Semantic) -> Self
A faint color behind the field, to call attention to it.
Sourcepub fn note_text(self, note: Option<String>, tone: Tone) -> Self
pub fn note_text(self, note: Option<String>, tone: Tone) -> Self
Something to know under the content, with an icon, which is not an error. An error replaces it.
Sourcepub fn validate(
self,
value: Binding<String>,
rule: impl Fn(&str) -> Result<(), String> + 'static,
) -> Self
pub fn validate( self, value: Binding<String>, rule: impl Fn(&str) -> Result<(), String> + 'static, ) -> Self
Validates value with rule (rules run in order; the first error shows).
Sourcepub fn show_errors(self, show: bool) -> Self
pub fn show_errors(self, show: bool) -> Self
Shows errors even for empty values (e.g. after a submit attempt).
Trait Implementations§
Auto Trait Implementations§
impl<V> !RefUnwindSafe for FormField<V>
impl<V> !Send for FormField<V>
impl<V> !Sync for FormField<V>
impl<V> !UnwindSafe for FormField<V>
impl<V> Freeze for FormField<V>where
V: Freeze,
impl<V> Unpin for FormField<V>where
V: Unpin,
impl<V> UnsafeUnpin for FormField<V>where
V: UnsafeUnpin,
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
impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<V> ViewExt for Vwhere
V: View,
impl<V> ViewExt for Vwhere
V: View,
Source§fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
fn padding(self, padding: impl Into<Insets>) -> Styled<Self>
Source§fn background(self, fill: impl Into<Fill>) -> Styled<Self>
fn background(self, fill: impl Into<Fill>) -> Styled<Self>
Source§fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
fn frame(self, width: Option<f32>, height: Option<f32>) -> Styled<Self>
None keeps the content size.