FormField

FormField

FormField is a legacy migration surface: a column that stacks a caption, whatever control you pass as its children, and one closing text line — help text or an error message. It also paints the caption in a status ink. They are legacy migration surfaces kept for existing pages; new code should prefer Input, whose label, hint, error and required props carry the same caption / message / required-marker trio inside the field itself.

  • Reach for it while migrating a page that wraps several different controls in one caption + message shell — the children can be any node, not only a text field.
  • For a plain text or number field, Input and NumberInput already render their own caption and message line.
  • The status does not validate anything: status only picks the ink on the caption and the box; you set it from your own validation.

Import

rust
1
2
use hikari_components::*;          // FormField, FormFieldStatus
use hikari_components::prelude::*; // rsx!, VNode

The Rust form is a plain function, FormField(FormFieldProps { … }). Inside rsx! every prop may be omitted — an omitted prop takes its default. The children are the field's default slot. The examples below omit the imports the page has just shown.

Label, required marker and help text

label renders the caption; an empty string means "no caption at all". required appends a red asterisk to it. help_text renders one line under the control. The children are whatever you put between them.

Rust
We only use it for sign-in.

Status and the error line

status paints the caption and the wrapper with one of four inks: FormFieldStatus::Default (the default), Error, Warning and Success. The message line shows help_text whenever it is set; only when help_text is unset does it show error_message (an error ink alone never suppresses the help text). With show_status left at its default (true), that line appears whenever error_message is set; turning it off hides the line while keeping the ink. The example passes help_text: None so each verdict is the one that speaks.

Rust
Must be at least 8 characters.
This path is on a slow volume.
Key verified.

Help text versus message, and any control as a child

help_text wins over error_message: when both are set, only the help line renders. That makes the help text the place for standing instructions and the message line for the current verdict, and it means you clear the help text when you want the verdict to speak. The children are a slot, so a field may hold a switch, a checkbox, a list — anything.

Rust
Shown to other people.

API

Rust

Props — FormField

PropTypeDefaultDescription
labelString""—
requiredboolfalse—
help_textOption<String>None—
error_messageOption<String>None—
statusFormFieldStatusFormFieldStatus::Default—
show_statusbooltrue—
classString""—
styleString""—
childrenElement(empty)—

Notes

  • The closing line holds one message, not two: help text and error message share the slot, and the help text always wins. A field that has to show both at once needs its own second line.
  • status is presentational. Nothing in this component inspects the children or decides whether the value is valid.
  • show_status only gates the message line; the status ink stays on the caption either way, and help_text still wins while it is set.
  • The message line always carries the hk-form-field-error-msg class, whatever the status is — the ink on the caption distinguishes warning and success, the line itself does not.
  • The children are rendered as given: no caption is programmatically associated with them, and no id is generated.
  • class and style land on the wrapper.

Accessibility

  • The caption is a <label> element with no for, so it is not bound to the child control. Give the child its own id and an explicit association, or use aria-labelledby, or a control that names itself.
  • The required marker is a * glyph: it is visual only. Set required on the control itself so assistive technology knows.
  • The message line is not wired to the control as a description; when it matters, connect it with aria-describedby on the child.
  • The status ink is colour-only — the message text has to say what is wrong too.

Related components

  • Input — the current text field with its own caption, hint, error line and required marker.
  • NumberInput — the number field with the trailing step column.