pub struct FormState {
pub fields: Vec<FormField>,
pub focused: usize,
pub cursors: Vec<usize>,
pub touched: HashSet<String>,
}Expand description
Form state: fields + focus + per-field cursor + touched set.
Fields§
§fields: Vec<FormField>§focused: usize§cursors: Vec<usize>Char-index cursor per field (relevant for Text / Integer / Float).
touched: HashSet<String>Field ids that the user has visited and then left. Callers render validation errors only for ids in this set (error-on-leave pattern).
Implementations§
Source§impl FormState
impl FormState
Sourcepub fn new(fields: Vec<FormField>) -> Self
pub fn new(fields: Vec<FormField>) -> Self
Build a new state. The cursor for each Text field starts at the end of its value; other kinds start at 0.
Sourcepub fn focus_next(&mut self) -> bool
pub fn focus_next(&mut self) -> bool
Move focus to the next visible field. Records the previously focused field as touched. Returns true if focus actually changed.
Sourcepub fn focus_prev(&mut self) -> bool
pub fn focus_prev(&mut self) -> bool
Move focus to the previous visible field.
Sourcepub fn handle_key(&mut self, key: KeyEvent) -> FormEvent
pub fn handle_key(&mut self, key: KeyEvent) -> FormEvent
Route a key event. Returns a FormEvent describing the outcome.
Sourcepub fn touch_all(&mut self)
pub fn touch_all(&mut self)
Mark the focused field as touched without moving focus. Useful when a caller commits a form (e.g. on Enter-save) and wants every row’s error visible.
Sourcepub fn untouch_all(&mut self)
pub fn untouch_all(&mut self)
Reset touched state — typically called when re-opening a form fresh.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FormState
impl RefUnwindSafe for FormState
impl Send for FormState
impl Sync for FormState
impl Unpin for FormState
impl UnsafeUnpin for FormState
impl UnwindSafe for FormState
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
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>
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>
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