Form
Submission and validation state for a group of fields.
This demo runs the real GPUI component on WebGPU, which this browser does not expose.
Try Chrome or Edge 113+, or Safari 26+. In Firefox, enable dom.webgpu.enabled.
You can also run it natively: cargo run -p showcase form
The demo failed to start in this browser.
You can run it natively instead: cargo run -p showcase form
Live examples are not supported on most mobile browsers yet — open this page on a desktop or tablet to run the demo.
Recent phones with WebGPU may manage it (downloads ~18 MB):
#Anatomy
Import the component's parts and compose them under its root:
use base_gpui::form::{
Form,
};
Form::new();
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.
#Form
Public renderable part of the Form component.
use base_gpui::form::Form;
Form::new()
.id("example-id")
.validation_mode("example-id")
.errors(/* errors: FormErrors */)
.aria_label("aria label")
.on_form_submit(|/* callback arguments */| { /* handle change */ })
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a Form with its default configuration. |
.child | pub fn child(mut self, child: impl IntoElement) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl IntoElement>) -> Self
Adds multiple typed children in iteration order. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.validation_mode | pub fn validation_mode(mut self, validation_mode: FieldValidationMode) -> Self
Sets the validation mode configuration for this part. |
.errors | pub fn errors(mut self, errors: FormErrors) -> Self
Sets the errors configuration for this part. |
.aria_label | pub fn aria_label(mut self, aria_label: impl Into<SharedString>) -> Self
Sets a literal accessible name for this part. |
.on_form_submit | pub fn on_form_submit(mut self, on_form_submit: impl Fn(FormValues, FormSubmitDetails, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when form submit occurs. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(FormStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. Form also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#Accessibility
Keyboard interaction and accessibility semantics are implemented by the component, independently of visual styling. Known limitations caused by missing GPUI accessibility primitives are documented in the module source and are not silently approximated.
#Stability
Base GPUI is pre-1.0. Builder names and state types may evolve as GPUI and this port mature.