pub struct Form {
pub message: String,
pub fields: Vec<FormField>,
/* private fields */
}Expand description
A multi-field form rendered as a tabbed pane with a virtual “Submit” tab.
Each FormField gets its own full pane. A tab bar at the top shows all fields plus a final Submit tab. Navigate between tabs with Tab/BackTab or arrow keys (for non-text fields). The active field’s widget receives all other input.
§Construction
use tui::{Form, FormField, FormFieldKind, TextField, SelectOption, RadioSelect};
let form = Form::new("Configure project".to_string(), vec![
FormField {
name: "name".to_string(),
label: "Project name".to_string(),
description: Some("The directory name for your project".to_string()),
required: true,
kind: FormFieldKind::Text(TextField::new(String::new())),
},
]);§Messages
Form implements Component with Message = FormMessage:
FormMessage::Close— Emitted on Esc.FormMessage::Submit— Emitted on Enter while the Submit tab is focused.
§Serialization
to_json() serializes all field values to a serde_json::Value object, keyed by each field’s name.
§FormField
A single field within the form:
name— Machine-readable key (used in JSON output).label— Human-readable label shown in the tab bar and pane header.description— Optional help text shown below the field.required— Iftrue, an asterisk is shown next to the label.kind— The backing widget, as aFormFieldKind.
§FormFieldKind
Text(TextField)— Single-line text input.Number(NumberField)— Numeric input.Boolean(Checkbox)— Toggle rendered as[x]/[ ].SingleSelect(RadioSelect)— Radio button list.MultiSelect(MultiSelect)— Checkbox list.
§See also
TextField— Text input widget.Checkbox— Boolean toggle.RadioSelect— Single-select list.MultiSelect— Multi-select list.FocusRing— Used internally for tab navigation.
Fields§
§message: String§fields: Vec<FormField>Implementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Form
impl RefUnwindSafe for Form
impl Send for Form
impl Sync for Form
impl Unpin for Form
impl UnsafeUnpin for Form
impl UnwindSafe for Form
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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