pub struct Form {
pub title: Option<String>,
pub fields: Vec<Field>,
pub mode: FormMode,
/* private fields */
}Expand description
A vim-modal form. Holds an ordered list of fields, the focused
index, the current FormMode, an optional title, and a submit
closure consumed on first call.
Fields§
§title: Option<String>§fields: Vec<Field>§mode: FormModeImplementations§
Source§impl Form
impl Form
Sourcepub fn with_title(self, title: impl Into<String>) -> Self
pub fn with_title(self, title: impl Into<String>) -> Self
Set an optional title row rendered above the fields.
Sourcepub fn with_field(self, field: Field) -> Self
pub fn with_field(self, field: Field) -> Self
Append a field to the form. Order matters — first field is
focused by default and j/k walks the list in order.
Sourcepub fn with_submit(self, submit: SubmitFn) -> Self
pub fn with_submit(self, submit: SubmitFn) -> Self
Register the submit closure. Consumed via Option::take on
the first successful submit.
Sourcepub fn focused_field(&self) -> Option<&Field>
pub fn focused_field(&self) -> Option<&Field>
Borrow the focused field, if any.
Sourcepub fn focused_field_mut(&mut self) -> Option<&mut Field>
pub fn focused_field_mut(&mut self) -> Option<&mut Field>
Mutably borrow the focused field, if any.
Source§impl Form
impl Form
Sourcepub fn handle_input(&mut self, input: Input) -> Option<FormEvent>
pub fn handle_input(&mut self, input: Input) -> Option<FormEvent>
Route a key event through the form. Returns an event if the keystroke produced one (focus moved, value changed, submit fired, etc.).
Source§impl Form
impl Form
Sourcepub fn try_submit(&mut self) -> Option<SubmitOutcome>
pub fn try_submit(&mut self) -> Option<SubmitOutcome>
Validate every field and, on success, fire the submit closure
(consumed via Option::take). Returns:
Some(SubmitOutcome::Ok)/Some(SubmitOutcome::Err(_))— submit ran (or no submit was registered, in which caseOk).None— validation failed; per-field errors populated.
Source§impl Form
impl Form
Sourcepub fn validate_focused(&mut self) -> bool
pub fn validate_focused(&mut self) -> bool
Validate the focused field. Returns the same boolean as
validate_field.