pub struct Form { /* private fields */ }Expand description
HeroUI Form: a vertical field stack that collects a named submission.
Implementations§
Source§impl Form
impl Form
Sourcepub fn validation_errors(self, errors: ValidationErrors) -> Self
pub fn validation_errors(self, errors: ValidationErrors) -> Self
validationErrors — HeroUI v3’s ValidationErrors record:
server-side errors mapped by field name
(Record<string, string | string[]>).
The form routes the record; the fields display it. Each entry lands in
the named field’s own state and error slot — there is no form-level
message stack. Delivery is receipted per field: each field’s own state
stores the record’s ValidationErrors::revision beside its routed
messages, so re-rendering with a clone keeps the per-field state (an
edit stays suppressed, and reordering or replacing the registrations
re-arms nothing), while any freshly built record re-arms every named
field it mentions, content-equal or not. Names no registered field
displays neither block nor render.
Identity is the caller’s to preserve: keep one record for as long as
the response is current and pass a Clone of it each frame; building
a fresh record per frame — ValidationErrors::new() inline, or a
re-run builder chain — is a new server response every frame and re-arms
every named field it mentions, even with identical content. This is
React Stately’s reference identity, unchanged.
Sourcepub fn validation_behavior(self, behavior: ValidationBehavior) -> Self
pub fn validation_behavior(self, behavior: ValidationBehavior) -> Self
validationBehavior — whether a failed field blocks submission.
Sourcepub fn field(self, field: FormField) -> Self
pub fn field(self, field: FormField) -> Self
Registers a named field, so its value appears in the submission.
Sourcepub fn on_submit(
self,
f: impl Fn(&FormData, &mut Window, &mut App) + 'static,
) -> Self
pub fn on_submit( self, f: impl Fn(&FormData, &mut Window, &mut App) + 'static, ) -> Self
onSubmit — receives the collected submission.
Sourcepub fn on_reset(self, f: impl Fn(&mut Window, &mut App) + 'static) -> Self
pub fn on_reset(self, f: impl Fn(&mut Window, &mut App) + 'static) -> Self
onReset — fires after the registered fields are restored.
Sourcepub fn on_invalid(
self,
f: impl Fn(&FormData, &mut Window, &mut App) + 'static,
) -> Self
pub fn on_invalid( self, f: impl Fn(&FormData, &mut Window, &mut App) + 'static, ) -> Self
onInvalid — runs instead of onSubmit when validation blocks it.
Blocked means a required field with no value, or a field whose own
resolved validity is in error (validate, isInvalid, the field’s
validationErrors, an HTML5 attribute violation, or a server message
routed to it by the form’s validationErrors record) — and only under
ValidationBehavior::Native; Allow submits regardless, as v3’s
does. Disabled and read-only fields never block.
Sourcepub fn submit_handler(&self) -> Arc<dyn Fn(&mut Window, &mut App) + 'static> ⓘ
pub fn submit_handler(&self) -> Arc<dyn Fn(&mut Window, &mut App) + 'static> ⓘ
The handler a submit button calls: collects the submission, then routes
it to onSubmit or onInvalid.
gpui gives a child no way to reach its form, so the caller wires this to
the button in place of <button type="submit">. The form root’s Enter
key handler runs the same implementation, so a submission is decided
identically however it arrived.
Sourcepub fn reset_handler(&self) -> Arc<dyn Fn(&mut Window, &mut App) + 'static> ⓘ
pub fn reset_handler(&self) -> Arc<dyn Fn(&mut Window, &mut App) + 'static> ⓘ
The handler a reset button calls: restores every field that declared a
default, hides the routed server errors, then fires onReset.
Hiding is a clear, not a rewind: each field keeps its delivery receipt
(see SetServerErrors), so a re-render passing a clone keeps the
messages hidden, and only a genuinely new record re-arms.
Trait Implementations§
Source§impl IntoElement for Form
impl IntoElement for Form
Source§type Element = ViewElement<Form>
type Element = ViewElement<Form>
Source§fn into_element(self) -> Self::Element
fn into_element(self) -> Self::Element
Element.Source§fn into_any_element(self) -> AnyElement
fn into_any_element(self) -> AnyElement
AnyElement.Source§impl ParentElement for Form
impl ParentElement for Form
Source§fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>)
fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>)
Source§fn child(self, child: impl IntoElement) -> Selfwhere
Self: Sized,
fn child(self, child: impl IntoElement) -> Selfwhere
Self: Sized,
Source§fn children(self, children: impl IntoIterator<Item = impl IntoElement>) -> Selfwhere
Self: Sized,
fn children(self, children: impl IntoIterator<Item = impl IntoElement>) -> Selfwhere
Self: Sized,
Source§impl RenderOnce for Form
impl RenderOnce for Form
Source§fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement
Render::render() method
which takes a mutable reference.Auto Trait Implementations§
impl !RefUnwindSafe for Form
impl !Send for Form
impl !Sync for Form
impl !UnwindSafe for Form
impl Freeze for Form
impl Unpin for Form
impl UnsafeUnpin for Form
Blanket Implementations§
Source§impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
impl<E> AnimationExt for Ewhere
E: IntoElement + 'static,
Source§fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
fn with_animation(
self,
id: impl Into<ElementId>,
animation: Animation,
animator: impl Fn(Self, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
Source§fn with_animations(
self,
id: impl Into<ElementId>,
animations: Vec<Animation>,
animator: impl Fn(Self, usize, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
fn with_animations(
self,
id: impl Into<ElementId>,
animations: Vec<Animation>,
animator: impl Fn(Self, usize, f32) -> Self + 'static,
) -> AnimationElement<Self>where
Self: Sized,
Source§fn with_spring<T>(
self,
id: impl Into<ElementId>,
animation: SpringAnimation<T>,
animator: impl FnOnce(Self, <T as SpringTarget>::Output) -> Self + 'static,
) -> SpringAnimationElement<Self>
fn with_spring<T>( self, id: impl Into<ElementId>, animation: SpringAnimation<T>, animator: impl FnOnce(Self, <T as SpringTarget>::Output) -> Self + 'static, ) -> SpringAnimationElement<Self>
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FluentBuilder for Twhere
T: IntoElement,
impl<T> FluentBuilder for Twhere
T: IntoElement,
Source§fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
fn map<U>(self, f: impl FnOnce(Self) -> U) -> Uwhere
Self: Sized,
Source§fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
fn when(self, condition: bool, then: impl FnOnce(Self) -> Self) -> Selfwhere
Self: Sized,
Source§fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
fn when_else(
self,
condition: bool,
then: impl FnOnce(Self) -> Self,
else_fn: impl FnOnce(Self) -> Self,
) -> Selfwhere
Self: Sized,
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> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().