Data Entry
Text and number fields
Text, long text, search, exact numbers and money.
import { MoneyField, NumberField, SearchField, TextArea, TextField } from 'faifo-design'TextField, TextArea, SearchField, NumberField and MoneyField share one field contract:
label, help, error, disabled and read-only states. Numbers are typed and shown in the reader's
language and submitted as a plain decimal.
#When to use
- Use
NumberFieldfor a quantity andMoneyFieldfor an amount with its currency; both keep exact decimals. - Use
SearchFieldfor a query that filters what is on screen. - Use
TextAreawhen the value is more than one line.
#Notes
showFieldError and clearFieldError let a client island show a server refusal under the field
that caused it, exactly where Field renders its own error.
#Examples
Each example is a specimen of the package catalogue, rendered on the server exactly as shown in its code.
#Scalar fields
Text, long text, search, exact numeric and money values share one field contract.
Show codeHide code
import { Grid, MoneyField, NumberField, SearchField, TextArea, TextField } from 'faifo-design'
export const Example = () => (
<Grid
columns={2}
items={[
<TextField id="customer" name="customer" label="Customer" value="An Việt" required />,
<SearchField id="reference" name="reference" label="Reference" value="SO-1042" />,
<NumberField id="quantity" name="quantity" label="Quantity" value="12" min="0" />,
<MoneyField id="total" name="total" label="Total" value="18450000.00" />,
<TextArea
id="note"
name="note"
label="Internal note"
value="Deliver before 17:00."
span="full"
/>,
]}
/>
)#Contract
#Server field errors after a fetch submit
A form that posts with fetch learns about a field error only after the page has rendered,
so it cannot pass error to Field. Do not call setCustomValidity/reportValidity for
it: the browser bubble covers the help text, disappears on the next click and leaves nothing
for a screen reader to find again. Call showFieldError(control, message) from
faifo-design with the control the server named (for a checkbox or radio
group, any of its inputs). It adds the same field-error markup Field renders with
error, after the help, sets data-invalid on the Field and aria-invalid plus the error
ID in aria-describedby on the control (on the group and every choice for an option group),
and focuses the control; pass { focus: false } when another error already took focus.
A second call replaces the message. The next input or change inside that Field removes
it and restores the attributes it found; the returned function and
clearFieldError(control) remove it earlier, including an error the Field was rendered with.
A check that answers while the person is still typing (an email someone already uses) passes
{ focus: false, announce: true }: focus stays in the field, and the message is an alert that
is read out when it appears.
A control outside a Field is a no-op, so say that message elsewhere (a toast or a Notice).
#API
Generated from the package source. A property without a description has none in the source yet.
#clearFieldErrorFunction
Removes a message showFieldError put on the Field holding control, or one the Field was rendered with. Does nothing when the Field shows no error.
function clearFieldError(control: Element): void| Parameter | Type |
|---|---|
controlrequired | Element |
| Returns | void |
#showFieldErrorFunction
Shows message under the Field that holds control, as Field renders its error, and focuses the control. A second call replaces the first message. Returns a function that removes the message, which also happens on the next input or change in the Field. announce is for a check that answers while the person is still typing in the Field: focus stays where it is, so the message is an alert and is read out when it appears.
function showFieldError(control: HTMLElement, message: string, options?: { focus?: boolean | undefined; announce?: boolean | undefined; } | undefined) => (): void| Parameter | Type |
|---|---|
controlrequired | HTMLElement |
messagerequired | string |
options | { focus?: boolean, announce?: boolean } |
| Returns | () => void |
#formatLocaleNumberFunction
A plain decimal written for a language ("1.800.000" in Vietnamese). Anything else, such as text a reader typed that is not a number, is shown as it is.
function formatLocaleNumber(value: string | number | null | undefined, locale: string): string| Parameter | Type |
|---|---|
valuerequired | string | number | null | undefined |
localerequired | string |
| Returns | string |
#numberControlValueFunction
What a control holds as data: the plain decimal of a localized number field (its text, or the given text such as its default value), and the text unchanged for any other control or a typo.
function numberControlValue(control: { value?: string | undefined; getAttribute?: ((name: string) => string | null) | undefined; }, text?: string | undefined): string| Parameter | Type |
|---|---|
controlrequired | { value?: string, getAttribute?: (name: string) => string | null } |
text | string |
| Returns | string |
#parseLocaleNumberFunction
The plain decimal ("-1234.5") a reader meant, or null when the text is not a number in that language. Grouping marks are accepted only in groups of three; a single mark that cannot be grouping (Vietnamese "12.5") reads as the decimal point of the other habit. Empty text stays empty.
function parseLocaleNumber(text: string, locale: string): string | null| Parameter | Type |
|---|---|
textrequired | string |
localerequired | string |
| Returns | string | null |
#MoneyFieldComponent
| Property | Description | Type | Default |
|---|---|---|---|
idrequired | – | string | – |
namerequired | – | string | – |
labelrequired | – | string | – |
size | Opt-in matched input/action height: 36px desktop, 44px mobile. | 'default' | 'large' | – |
labelHidden | Embedded controls share the frame of a compound field. | boolean | – |
required | – | boolean | – |
disabled | – | boolean | – |
help | – | string | null | – |
span | – | 'half' | 'full' | – |
width | How long the value is: the control is no wider than it needs (FieldFrame). | 'xs' | 'sm' | 'md' | – |
issues | – | readonly FieldIssue[] | – |
error | – | string | null | – |
value | – | string | number | boolean | null | – |
prefix | – | JSXChild | – |
suffix | – | JSXChild | – |
align | – | 'start' | 'center' | 'end' | 'end' |
appearance | – | 'default' | 'embedded' | – |
placeholder | – | string | null | – |
readOnly | – | boolean | – |
min | – | string | number | – |
max | – | string | number | – |
step | – | string | null | – |
locale | Type and show the number as this language writes it: "28.600" is 28600 in vi. Submits the plain decimal through the design-system runtime; without a locale the native number input is kept. | string | – |
currency | – | string | – |
precision | – | number | – |
#NumberFieldComponent
| Property | Description | Type | Default |
|---|---|---|---|
idrequired | – | string | – |
namerequired | – | string | – |
labelrequired | – | string | – |
size | Opt-in matched input/action height: 36px desktop, 44px mobile. | 'default' | 'large' | – |
labelHidden | Embedded controls share the frame of a compound field. | boolean | – |
required | – | boolean | – |
disabled | – | boolean | – |
help | – | string | null | – |
span | – | 'half' | 'full' | – |
width | How long the value is: the control is no wider than it needs (FieldFrame). | 'xs' | 'sm' | 'md' | – |
issues | – | readonly FieldIssue[] | – |
error | – | string | null | – |
value | – | string | number | boolean | null | – |
prefix | – | JSXChild | – |
suffix | – | JSXChild | – |
align | – | 'start' | 'center' | 'end' | – |
appearance | – | 'default' | 'embedded' | – |
placeholder | – | string | null | – |
readOnly | – | boolean | – |
min | – | string | number | – |
max | – | string | number | – |
step | – | string | null | – |
locale | Type and show the number as this language writes it: "28.600" is 28600 in vi. Submits the plain decimal through the design-system runtime; without a locale the native number input is kept. | string | – |
#SearchFieldComponent
| Property | Description | Type | Default |
|---|---|---|---|
idrequired | – | string | – |
namerequired | – | string | – |
labelrequired | – | string | – |
size | Opt-in matched input/action height: 36px desktop, 44px mobile. | 'default' | 'large' | – |
value | – | string | number | boolean | null | – |
prefix | – | JSXChild | – |
suffix | – | JSXChild | – |
inputMode | – | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url' | – |
align | – | 'start' | 'center' | 'end' | – |
maxLength | – | number | – |
minLength | – | number | – |
pattern | – | string | – |
labelHidden | Embedded controls share the frame of a compound field. | boolean | – |
appearance | – | 'default' | 'embedded' | – |
placeholder | – | string | null | – |
required | – | boolean | – |
disabled | – | boolean | – |
readOnly | – | boolean | – |
help | – | string | null | – |
span | – | 'half' | 'full' | – |
width | How long the value is: the control is no wider than it needs (FieldFrame). | 'xs' | 'sm' | 'md' | – |
autocomplete | – | string | null | – |
issues | – | readonly FieldIssue[] | – |
error | – | string | null | – |
clearable | – | boolean | – |
clearLabel | – | string | – |
#TextAreaComponent
| Property | Description | Type | Default |
|---|---|---|---|
idrequired | – | string | – |
namerequired | – | string | – |
labelrequired | – | string | – |
size | Opt-in matched input/action height: 36px desktop, 44px mobile. | 'default' | 'large' | – |
labelHidden | Embedded controls share the frame of a compound field. | boolean | – |
required | – | boolean | – |
disabled | – | boolean | – |
help | – | string | null | – |
span | – | 'half' | 'full' | – |
width | How long the value is: the control is no wider than it needs (FieldFrame). | 'xs' | 'sm' | 'md' | – |
issues | – | readonly FieldIssue[] | – |
error | – | string | null | – |
value | – | string | number | boolean | null | – |
rows | – | number | – |
resize | – | 'vertical' | 'none' | – |
maxLength | – | number | – |
minLength | – | number | – |
appearance | – | 'default' | 'embedded' | – |
placeholder | – | string | null | – |
readOnly | – | boolean | – |
#TextFieldComponent
| Property | Description | Type | Default |
|---|---|---|---|
idrequired | – | string | – |
namerequired | – | string | – |
labelrequired | – | string | – |
size | Opt-in matched input/action height: 36px desktop, 44px mobile. | 'default' | 'large' | – |
labelHidden | Embedded controls share the frame of a compound field. | boolean | – |
required | – | boolean | – |
disabled | – | boolean | – |
help | – | string | null | – |
span | – | 'half' | 'full' | – |
width | How long the value is: the control is no wider than it needs (FieldFrame). | 'xs' | 'sm' | 'md' | – |
issues | – | readonly FieldIssue[] | – |
error | – | string | null | – |
value | – | string | number | boolean | null | – |
prefix | – | JSXChild | – |
suffix | – | JSXChild | – |
inputMode | – | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url' | – |
align | – | 'start' | 'center' | 'end' | – |
maxLength | – | number | – |
minLength | – | number | – |
pattern | – | string | – |
appearance | – | 'default' | 'embedded' | – |
placeholder | – | string | null | – |
readOnly | – | boolean | – |
autocomplete | – | string | null | – |
type | – | 'text' | 'email' | 'tel' | 'password' | 'url' | 'text' |
#Types
#FieldIssue
| Property | Description | Type | Default |
|---|---|---|---|
pathrequired | – | string | – |
messagerequired | – | string | – |
#ScalarFieldProps
| Property | Description | Type | Default |
|---|---|---|---|
readOnlyWhen | In a RecordForm, lock/hide this field while the named peer has a non-empty value. | string | – |
hiddenWhen | – | string | – |
open | – | boolean | – |
onInput | Native input events, also emitted by progressively enhanced controls. | (event: Event) => void | – |
onChange | – | (event: Event) => void | – |
onBlur | – | (event: Event) => void | – |
idrequired | – | string | – |
namerequired | – | string | – |
labelrequired | – | string | – |
locale | Forward the host locale to date/time controls; omitted keeps their existing default. | 'vi' | 'en' | 'ja' | – |
size | Opt-in matched input/action height: 36px desktop, 44px mobile. | 'default' | 'large' | – |
layout | Keep an enhanced control and its label in one row at narrow widths. | 'inline' | – |
action | A command right after a short single-line entry, such as an Add or Apply Button. The entry keeps a compact width and Enter in it runs the command instead of the form's first submit button. | JSXChild | – |
value | – | string | number | boolean | null | – |
checked | – | boolean | 'indeterminate' | – |
submitValue | Legacy checkbox value used checked state; submitValue opts into separate form data. | string | – |
prefix | – | JSXChild | – |
suffix | – | JSXChild | – |
clearable | – | boolean | – |
clearLabel | – | string | – |
inputMode | – | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url' | – |
numberLocale | A number or decimal typed and shown as this language writes it ("1.800.000" in vi). The control becomes a text input; the design-system runtime submits the plain decimal ("1800000"). | string | – |
align | – | 'start' | 'center' | 'end' | – |
rows | – | number | – |
resize | – | 'vertical' | 'none' | – |
maxLength | – | number | – |
minLength | – | number | – |
pattern | – | string | – |
labelHidden | Embedded controls share the frame of a compound field. | boolean | – |
selectionHidden | Keep the selected value accessible while showing only the select chevron. | boolean | – |
appearance | – | 'default' | 'embedded' | – |
placeholder | – | string | null | – |
required | – | boolean | – |
disabled | – | boolean | – |
readOnly | – | boolean | – |
min | – | string | number | – |
max | – | string | number | – |
help | – | string | null | – |
options | – | readonly FieldOption[] | – |
optionsOrientation | How checkbox-group and radio options flow. horizontal (default) wraps them on a line; vertical lists one option per line under the shared label, for choices whose labels should scan as a column. | 'horizontal' | 'vertical' | – |
span | – | 'half' | 'full' | – |
width | How long the value is: the control is no wider than it needs (FieldFrame). | 'xs' | 'sm' | 'md' | – |
step | – | string | null | – |
autocomplete | – | string | null | – |
issues | – | readonly FieldIssue[] | – |
error | – | string | null | – |
#ScalarFieldBase
Shared field metadata. Each scalar exposes only the options it implements.
| Property | Description | Type | Default |
|---|---|---|---|
idrequired | – | string | – |
namerequired | – | string | – |
labelrequired | – | string | – |
size | Opt-in matched input/action height: 36px desktop, 44px mobile. | 'default' | 'large' | – |
labelHidden | Embedded controls share the frame of a compound field. | boolean | – |
required | – | boolean | – |
disabled | – | boolean | – |
help | – | string | null | – |
span | – | 'half' | 'full' | – |
width | How long the value is: the control is no wider than it needs (FieldFrame). | 'xs' | 'sm' | 'md' | – |
issues | – | readonly FieldIssue[] | – |
error | – | string | null | – |
#TextFieldProps
The properties of TextField, listed above.
#TextAreaProps
The properties of TextArea, listed above.
#NumberFieldProps
The properties of NumberField, listed above.
#MoneyFieldProps
The properties of MoneyField, listed above.
#SearchFieldProps
The properties of SearchField, listed above.