Functional Weave
Code in Rust

react.form.money-field

A money input with its currency symbol, locale separators and min/max, read and checked by form.money-input.

React ^19 · TypeScript only A React component: use it from a TypeScript project with React installed. A client component ("use client").

1.0.0 · published 2026-10-10 by charlie · Anterra

Pinned by 14 tests, run in TypeScript.

What it does

An amount of money in one known currency, typed the way the person's locale writes numbers, read as integer minor units by `form.money-input`. It is `react.form.text-field` with the currency symbol as a prefix (or a suffix, for currencies written after the amount), a decimal keyboard and no spell check.

"use client";
import { MoneyField } from "#fune/react.form.money-field@^1";
import { parseMoneyInput, formatMoneyInput } from "#fune/form.money-input@^1";

const rules = { label: "Amount", required: true, min: 100, max: 1000000, allowNegative: false };
<MoneyField id="amount" label="How much do you want to send, in pounds?" currency="GBP" locale="en-GB"
  rules={rules} hint="For example, 1,234.50" value={text} onChange={setText} showError={submitted} />

// On submit, in the browser or on the server:
const check = parseMoneyInput(text, "GBP", "en-GB", rules); // check.amount = { minor: 123450, currency: "GBP" }
// To edit a stored amount: setText(formatMoneyInput(stored, "en-GB"))  // "1,234.50"

For example

  1. pounds: £ as an aria-hidden prefix, a decimal keyboard, no spell check

    <MoneyField
      id="amount"
      label="Amount, in pounds"
      currency="GBP"
      locale="en-GB"
      rules={{"label":"Amount","required":true,"min":100,"max":1000000,"allowNegative":false}}
    />

    renders

    <div class="fune-field fune-money-field"><label class="fune-label" for="amount">Amount, in pounds</label><div class="fune-input-wrapper"><div class="fune-input-prefix" aria-hidden="true">£</div><input class="fune-input" id="amount" type="text" inputMode="decimal" spellCheck="false" required="" name="amount"/></div></div>
  2. kronor in sv-SE: kr is written after the amount, so it is a suffix

    <MoneyField
      id="belopp"
      label="Amount, in kronor"
      currency="SEK"
      locale="sv-SE"
      rules={{"label":"Amount","required":true,"min":null,"max":null,"allowNegative":false}}
      value="1 234,50"
    />

    renders

    <div class="fune-field fune-money-field"><label class="fune-label" for="belopp">Amount, in kronor</label><div class="fune-input-wrapper"><input class="fune-input" id="belopp" type="text" inputMode="decimal" spellCheck="false" required="" name="belopp" value="1 234,50"/><div class="fune-input-suffix" aria-hidden="true">kr</div></div></div>

The function

Written for React ^19, in TypeScript only. A component: it takes its props and renders HTML, which the tests below pin exactly.

A React capability: React ^19 · TypeScript only. This capability has no Rust implementation, so it is shown in TypeScript. A Rust project cannot use it: fune build stops and names where it was required. Your choice of Rust is kept for every other page.

export function MoneyField(props: MoneyFieldProps): JSX.Element

Its props, MoneyFieldProps. A ? marks one the caller may leave out.

labelReactNodethe question; say the currency too ("How much do you earn, in pounds?"), since the symbol is hidden from screen readers
currencystringISO 4217 code, such as GBP; its symbol is shown beside the input
localestringBCP 47 locale, such as en-GB or de-DE: how digits are grouped and the decimal marked
rulesMoneyRulesrules.label names the amount in messages; required, min and max in minor units
id?stringthe input's id; React's useId() when left out
name?stringwhat the text is submitted as; the id when left out
hint?ReactNodehelp under the label, such as "For example, 1,234.50"
showError?booleancheck the current text and show the message: after the field is touched or the form submitted
error?ReactNodean error to show instead, such as the server's answer; marks the input invalid
value?stringthe text, for a controlled input (with onChange); formatMoneyInput writes an amount back
defaultValue?stringthe starting text, for an uncontrolled one
onChange?(value: string) => voidcalled with the text as the person types; parseMoneyInput turns it into minor units
onBlur?() => voidcalled when the input loses focus, to mark the field touched
autoComplete?stringtransaction-amount for a payment, or off
disabled?booleanshown but not editable, and not submitted
className?stringadded to the wrapper's classes
rendersJSX.Element

The type it declares, generated into your project

/** One amount of money in a known currency, typed as the person's locale writes it. */
export interface MoneyFieldProps {
  /** the question; say the currency too ("How much do you earn, in pounds?"), since the symbol is hidden from screen readers */
  readonly label: ReactNode;
  /** ISO 4217 code, such as GBP; its symbol is shown beside the input */
  readonly currency: string;
  /** BCP 47 locale, such as en-GB or de-DE: how digits are grouped and the decimal marked */
  readonly locale: string;
  /** rules.label names the amount in messages; required, min and max in minor units */
  readonly rules: MoneyRules;
  /** the input's id; React's useId() when left out */
  readonly id?: string;
  /** what the text is submitted as; the id when left out */
  readonly name?: string;
  /** help under the label, such as "For example, 1,234.50" */
  readonly hint?: ReactNode;
  /** check the current text and show the message: after the field is touched or the form submitted */
  readonly showError?: boolean;
  /** an error to show instead, such as the server's answer; marks the input invalid */
  readonly error?: ReactNode;
  /** the text, for a controlled input (with onChange); formatMoneyInput writes an amount back */
  readonly value?: string;
  /** the starting text, for an uncontrolled one */
  readonly defaultValue?: string;
  /** called with the text as the person types; parseMoneyInput turns it into minor units */
  readonly onChange?: (value: string) => void;
  /** called when the input loses focus, to mark the field touched */
  readonly onBlur?: () => void;
  /** transaction-amount for a payment, or off */
  readonly autoComplete?: string;
  /** shown but not editable, and not submitted */
  readonly disabled?: boolean;
  /** added to the wrapper's classes */
  readonly className?: string;
}

Your code names it in one line, in the file that uses it

import { MoneyField } from "#fune/react.form.money-field@^1";
impl/typescript.tsx · 55 lines · open · raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

"use client";

import { useId, useState, type JSX, type ReactNode } from "react";
import { moneyInputFormat, parseMoneyInput } from "./form_money_input.ts";  ← from form.money-input ^1.0.0 · built alongside by fune
import { TextField } from "./react_form_text_field.ts";  ← from react.form.text-field ^1.0.0 · built alongside by fune
import type { MoneyFieldProps } from "./react_form_money_field_types.ts";

function present(node: ReactNode): boolean {
  return node !== null && node !== undefined && node !== false && node !== "";
}

/**
 * The GOV.UK text input with a currency prefix (or suffix, for currencies
 * written after the amount), a decimal keyboard and no spell check. What is
 * typed stays text: parseMoneyInput reads it as integer minor units for the
 * currency, the way the locale writes numbers, and checks the rules, so the
 * server can read the same text to the same Money. The symbol is aria-hidden,
 * as GOV.UK does, so the label has to say the currency.
 */
export function MoneyField(props: MoneyFieldProps): JSX.Element {
  const auto = useId();
  const { label, currency, locale, rules, hint, showError, error, value, defaultValue, onChange, onBlur, autoComplete, disabled, className } = props;
  const id = props.id ?? auto;
  const [own, setOwn] = useState<string>(defaultValue ?? "");
  const current = value ?? own;
  // Both throw for an unknown currency or locale: a bug in the page, not
  // something the person typed.
  const format = moneyInputFormat(currency, locale);
  const check = parseMoneyInput(current, currency, locale, rules);
  const shown: ReactNode = present(error) ? error : showError && !check.valid ? check.message : null;
  return (
    <TextField
      id={id}
      name={props.name ?? id}
      label={label}
      hint={hint}
      error={shown}
      value={value}
      defaultValue={value === undefined ? defaultValue : undefined}
      onChange={(text) => {
        setOwn(text);
        onChange?.(text);
      }}
      onBlur={onBlur}
      inputMode="decimal"
      spellCheck={false}
      autoComplete={autoComplete}
      prefix={format.symbolBefore ? format.symbol : undefined}
      suffix={format.symbolBefore ? undefined : format.symbol}
      required={rules.required || undefined}
      disabled={disabled}
      className={className ? `fune-money-field ${className}` : "fune-money-field"}
    />
  );
}

Install

npm install react react-dom
fune build

With that line in your source, in a TypeScript project (language typescript in fune.project) with React ^19 installed (Functional Weave does not ship it, and fune build stops with the npm install line if it is missing), fune build resolves it and its 2 dependencies, pins them in fune.lock, downloads only the TypeScript package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. Or pin a range in fune.project and build in one step:

fune add react.form.money-field
Download for TypeScript react.form.money-field-1.0.0-typescript.fune · 22,358 bytes sha256 707595921dd4a6e8e22aefcfcc4f5495e66edcff75a340b6462767c7dfbe92cf

The manifest, vectors and README with only the TypeScript implementation. Install it without the registry with fune add ./react.form.money-field-1.0.0-typescript.fune, or fetch it from a terminal with fune pull react.form.money-field@1.0.0:typescript.

It is React ^19 · TypeScript only, so there is no package for Python or Rust. The full package is one file too: react.form.money-field-1.0.0.fune, 22,330 bytes, sha256 8a9e82c113a0366d46b1623aa88a77f728ef65c5c5c26cb7ae47ad6b4385df4a.

Customise it in your app

The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.

before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.

// fune: before react.form.money-field

after — your function gets the result and the arguments, and returns the final result.

// fune: after react.form.money-field

replace — inside this capability’s code only, calls to a dependency go to your function, with the same signature. Other capabilities that use it are unaffected; write in * to replace it everywhere.

// fune: replace form.money-input in react.form.money-field
// fune: replace react.form.text-field in react.form.money-field

step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show react.form.money-field --steps.

// fune: step react.form.money-field after <n|label>

Tests

A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript alone, with the React in tooling/react, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json. A component’s tests are render tests: the props go in, and the HTML renderToStaticMarkup makes of them has to match exactly; a React warning during the render fails the test.

  1. pounds: £ as an aria-hidden prefix, a decimal keyboard, no spell check

    <MoneyField
      id="amount"
      label="Amount, in pounds"
      currency="GBP"
      locale="en-GB"
      rules={{"label":"Amount","required":true,"min":100,"max":1000000,"allowNegative":false}}
    />

    renders

    <div class="fune-field fune-money-field"><label class="fune-label" for="amount">Amount, in pounds</label><div class="fune-input-wrapper"><div class="fune-input-prefix" aria-hidden="true">£</div><input class="fune-input" id="amount" type="text" inputMode="decimal" spellCheck="false" required="" name="amount"/></div></div>
  2. kronor in sv-SE: kr is written after the amount, so it is a suffix

    <MoneyField
      id="belopp"
      label="Amount, in kronor"
      currency="SEK"
      locale="sv-SE"
      rules={{"label":"Amount","required":true,"min":null,"max":null,"allowNegative":false}}
      value="1 234,50"
    />

    renders

    <div class="fune-field fune-money-field"><label class="fune-label" for="belopp">Amount, in kronor</label><div class="fune-input-wrapper"><input class="fune-input" id="belopp" type="text" inputMode="decimal" spellCheck="false" required="" name="belopp" value="1 234,50"/><div class="fune-input-suffix" aria-hidden="true">kr</div></div></div>
  3. a hint and a controlled value

    <MoneyField
      id="amount"
      label="Amount, in pounds"
      currency="GBP"
      locale="en-GB"
      rules={{"label":"Amount","required":true,"min":100,"max":1000000,"allowNegative":false}}
      hint="For example, 1,234.50"
      value="1,234.50"
    />

    renders

    <div class="fune-field fune-money-field"><label class="fune-label" for="amount">Amount, in pounds</label><div class="fune-hint" id="amount-hint">For example, 1,234.50</div><div class="fune-input-wrapper"><div class="fune-input-prefix" aria-hidden="true">£</div><input class="fune-input" id="amount" type="text" inputMode="decimal" spellCheck="false" required="" aria-describedby="amount-hint" name="amount" value="1,234.50"/></div></div>
  4. empty and required with showError: Enter amount

    <MoneyField
      id="amount"
      label="Amount, in pounds"
      currency="GBP"
      locale="en-GB"
      rules={{"label":"Amount","required":true,"min":100,"max":1000000,"allowNegative":false}}
      showError
      value=""
    />

    renders

    <div class="fune-field fune-field--error fune-money-field"><label class="fune-label" for="amount">Amount, in pounds</label><p class="fune-error-message" id="amount-error"><span class="fune-visually-hidden">Error:</span> Enter amount</p><div class="fune-input-wrapper"><div class="fune-input-prefix" aria-hidden="true">£</div><input class="fune-input fune-input--error" id="amount" type="text" inputMode="decimal" spellCheck="false" required="" aria-describedby="amount-error" aria-invalid="true" name="amount" value=""/></div></div>
  5. below the minimum with showError: the amount in the message

    <MoneyField
      id="amount"
      label="Amount, in pounds"
      currency="GBP"
      locale="en-GB"
      rules={{"label":"Amount","required":true,"min":100,"max":1000000,"allowNegative":false}}
      showError
      value="0.50"
    />

    renders

    <div class="fune-field fune-field--error fune-money-field"><label class="fune-label" for="amount">Amount, in pounds</label><p class="fune-error-message" id="amount-error"><span class="fune-visually-hidden">Error:</span> Amount must be between £1.00 and £10,000.00</p><div class="fune-input-wrapper"><div class="fune-input-prefix" aria-hidden="true">£</div><input class="fune-input fune-input--error" id="amount" type="text" inputMode="decimal" spellCheck="false" required="" aria-describedby="amount-error" aria-invalid="true" name="amount" value="0.50"/></div></div>
  6. too many decimal places for the currency

    <MoneyField
      id="amount"
      label="Amount, in pounds"
      currency="GBP"
      locale="en-GB"
      rules={{"label":"Amount","required":true,"min":100,"max":1000000,"allowNegative":false}}
      showError
      value="12.345"
    />

    renders

    <div class="fune-field fune-field--error fune-money-field"><label class="fune-label" for="amount">Amount, in pounds</label><p class="fune-error-message" id="amount-error"><span class="fune-visually-hidden">Error:</span> Amount must not have more than 2 decimal places</p><div class="fune-input-wrapper"><div class="fune-input-prefix" aria-hidden="true">£</div><input class="fune-input fune-input--error" id="amount" type="text" inputMode="decimal" spellCheck="false" required="" aria-describedby="amount-error" aria-invalid="true" name="amount" value="12.345"/></div></div>
  7. de-DE reads 1.234,50 as valid: no error

    <MoneyField
      id="betrag"
      label="Betrag in Euro"
      currency="EUR"
      locale="de-DE"
      rules={{"label":"Amount","required":true,"min":100,"max":1000000,"allowNegative":false}}
      showError
      value="1.234,50"
    />

    renders

    <div class="fune-field fune-money-field"><label class="fune-label" for="betrag">Betrag in Euro</label><div class="fune-input-wrapper"><div class="fune-input-prefix" aria-hidden="true">€</div><input class="fune-input" id="betrag" type="text" inputMode="decimal" spellCheck="false" required="" name="betrag" value="1.234,50"/></div></div>
  8. en-GB grouping typed in a de-DE field is the wrong format

    <MoneyField
      id="betrag"
      label="Betrag in Euro"
      currency="EUR"
      locale="de-DE"
      rules={{"label":"Amount","required":true,"min":null,"max":null,"allowNegative":false}}
      showError
      value="1,234.50"
    />

    renders

    <div class="fune-field fune-field--error fune-money-field"><label class="fune-label" for="betrag">Betrag in Euro</label><p class="fune-error-message" id="betrag-error"><span class="fune-visually-hidden">Error:</span> Enter amount in the correct format, like 1.234,50</p><div class="fune-input-wrapper"><div class="fune-input-prefix" aria-hidden="true">€</div><input class="fune-input fune-input--error" id="betrag" type="text" inputMode="decimal" spellCheck="false" required="" aria-describedby="betrag-error" aria-invalid="true" name="betrag" value="1,234.50"/></div></div>
  9. yen has no minor unit: a whole number, prefix ¥

    <MoneyField
      id="yen"
      label="Amount, in yen"
      currency="JPY"
      locale="ja-JP"
      rules={{"label":"Amount","required":false,"min":null,"max":null,"allowNegative":false}}
      showError
      value="1.5"
    />

    renders

    <div class="fune-field fune-field--error fune-money-field"><label class="fune-label" for="yen">Amount, in yen</label><p class="fune-error-message" id="yen-error"><span class="fune-visually-hidden">Error:</span> Amount must be a whole number</p><div class="fune-input-wrapper"><div class="fune-input-prefix" aria-hidden="true">¥</div><input class="fune-input fune-input--error" id="yen" type="text" inputMode="decimal" spellCheck="false" aria-describedby="yen-error" aria-invalid="true" name="yen" value="1.5"/></div></div>
  10. no check until showError

    <MoneyField
      id="amount"
      label="Amount, in pounds"
      currency="GBP"
      locale="en-GB"
      rules={{"label":"Amount","required":true,"min":100,"max":1000000,"allowNegative":false}}
      defaultValue="abc"
    />

    renders

    <div class="fune-field fune-money-field"><label class="fune-label" for="amount">Amount, in pounds</label><div class="fune-input-wrapper"><div class="fune-input-prefix" aria-hidden="true">£</div><input class="fune-input" id="amount" type="text" inputMode="decimal" spellCheck="false" required="" name="amount" value="abc"/></div></div>
Show the other 4 tests
  1. an error passed in wins

    <MoneyField
      id="amount"
      label="Amount, in pounds"
      currency="GBP"
      locale="en-GB"
      rules={{"label":"Amount","required":true,"min":100,"max":1000000,"allowNegative":false}}
      showError
      value="5.00"
      error="You do not have enough money in this account"
    />

    renders

    <div class="fune-field fune-field--error fune-money-field"><label class="fune-label" for="amount">Amount, in pounds</label><p class="fune-error-message" id="amount-error"><span class="fune-visually-hidden">Error:</span> You do not have enough money in this account</p><div class="fune-input-wrapper"><div class="fune-input-prefix" aria-hidden="true">£</div><input class="fune-input fune-input--error" id="amount" type="text" inputMode="decimal" spellCheck="false" required="" aria-describedby="amount-error" aria-invalid="true" name="amount" value="5.00"/></div></div>
  2. name, autocomplete, disabled and a class of its own

    <MoneyField
      id="amount"
      name="amountText"
      label="Amount, in pounds"
      currency="GBP"
      locale="en-GB"
      rules={{"label":"Amount","required":true,"min":100,"max":1000000,"allowNegative":false}}
      autoComplete="transaction-amount"
      disabled
      className="app-amount"
    />

    renders

    <div class="fune-field fune-money-field app-amount"><label class="fune-label" for="amount">Amount, in pounds</label><div class="fune-input-wrapper"><div class="fune-input-prefix" aria-hidden="true">£</div><input class="fune-input" id="amount" type="text" autoComplete="transaction-amount" inputMode="decimal" spellCheck="false" required="" disabled="" name="amountText"/></div></div>
  3. an unknown locale throws: a bug in the page

    <MoneyField
      id="a"
      label="Amount"
      currency="GBP"
      locale="xx-YY"
      rules={{"label":"Amount","required":true,"min":100,"max":1000000,"allowNegative":false}}
    />

    error: unknown locale

  4. an unknown currency throws

    <MoneyField
      id="a"
      label="Amount"
      currency="ZZZ"
      locale="en-GB"
      rules={{"label":"Amount","required":true,"min":100,"max":1000000,"allowNegative":false}}
    />

    error: ZZZ

Verification

Verified by the operator, not the sandbox 14 test vectors declared; none run by the registry.

Verified locally by the registry's operator, not by the sandbox. This version was published with FUNE_VERIFY_MODE=inline-dev (the operator's import of the first-party registry, or a development server): the server validated the package - its manifest, signatures, imports, safety lint and test rules - but the registry did not run its test vectors in its sandbox. The operator runs them with `fune verify --all` before importing.

Signed by the registry with key fw-9dc887227da47575 (ed25519), over its integrity and this report's digest. The full report · JSON

More from the author

- **Never a float.** The text becomes `Money { minor, currency }` with `money.parse`'s strict rules: grouping must be real thousands, no more decimal places than the currency has (none for JPY), and a symbol typed in must be this currency's. - **Locale.** `de-DE` reads `1.234,50`, `fr-FR` `1 234,50`, `de-CH` `1'234.50`; `formatMoneyInput` writes an amount back the same way. Which side the symbol goes is the currency's, from `money.format`'s table (kr after, £ € ¥ before), not the locale's: a French page shows € as a prefix. - **Accessible.** The symbol is `aria-hidden`, as GOV.UK does, so say the currency in the label. Errors use `aria-describedby` and `aria-invalid` through `react.form.text-field`. - `showError` turns the check on; `error` shows another message instead. An unknown currency or locale throws: it is a bug in the page.

It is a client component. Classes: those of `react.form.text-field`, plus `fune-money-field` on the wrapper.

Sources: GOV.UK Design System, "Text input" (prefixes and suffixes) https://design-system.service.gov.uk/components/text-input/ .

## Notices

Portions derived from GOV.UK Frontend (https://github.com/alphagov/govuk-frontend), Copyright (c) 2017 Crown Copyright (Government Digital Service), under the MIT License; the full notice is in NOTICE.

Files

PathBytes
NOTICE1,220
README.md2,374
impl/typescript.tsx2,261
vectors.json10,188