Skip to content
Focsd homeFocsd homeFocsd
Forms

Currency field

An amount of money: plain number while editing, formatted for the page language on blur.

  • Tag: focsd-currency-field
  • Pattern: Spinbutton with locale-formatted currency
  • Category: Forms

Example

HTML
<div class="stack">
<focsd-currency-field
label="Price"
currency="EUR"
value="1234.5"
max="10000"></focsd-currency-field>
<focsd-currency-field
label="Budget"
currency="JPY"
currency-display="code"></focsd-currency-field>
</div>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-currency-field.js';
</script>
<focsd-currency-field label="Price" currency="EUR" value="1234.5" max="10000"></focsd-currency-field>

API

Attributes

AttributePropertyTypeDefault
currencycurrencystringUSD
currency-displaycurrencyDisplay'symbol' | 'narrowSymbol' | 'code' | 'name'symbol
minminstring | number | undefined—
maxmaxstring | number | undefined—
stepstepstring | number | undefined—
allow-negativeallowNegativebooleanfalse
namenamestring—
disableddisabledbooleanfalse
requiredrequiredbooleanfalse
readonlyreadOnlybooleanfalse
aria-labelhostAriaLabelstring | nullnull
aria-descriptionhostAriaDescriptionstring | nullnull
aria-labelledbyhostAriaLabelledBystring | nullnull
aria-describedbyhostAriaDescribedBystring | nullnull
label-positionlabelPosition'top' | 'start' | 'end' | undefined—
hinthintstring—
errorerror——
warningwarningstring | undefined—
successsuccessstring | undefined—
error-messageerrorMessagestring | undefined—
warning-messagewarningMessagestring | undefined—
warning-patternwarningPatternstring | undefined—
labellabelstring—
valuevaluestring—
typetype'text' | 'email' | 'password' | 'search' | 'tel' | 'url'text
placeholderplaceholderstring—
autocompleteautocompleteAutoFill—
minlengthminlengthnumber—
maxlengthmaxlengthnumber—
patternpatternstring | undefined—
sizesizenumber | undefined—
dirnamedirnamestring | undefined—
inputmodeinputMode——
enterkeyhintenterKeyHint——
autocapitalizeautocapitalize——
autocorrectautocorrect——
spellcheckspellcheck——

Methods

MethodDescription
setRangeText(replacement, start, end, selectMode)Replace text like the native method, on the plain number the person edits (1234.50, as shown while focused) rather than the formatted amount shown on blur. Updates value without firing input.
describedByIds()IDs to add to the inner control's aria-describedby: the hint, then the shown message.
checkValidity()True when the value is valid; otherwise fires invalid and returns false, like native.
reportValidity()Like checkValidity(), and also shows the browser's validation message when invalid.
setCustomValidity(message)Set (non-empty) or clear (empty string) a custom validation error, like native controls.
setValidityState(flags, message, anchor)For subclasses: set the validity flags and message. anchor is the element the browser points its message at.
validate()Show (or clear) the error from the control's own checks: required, type, pattern, min, max and the like. Uses error-message, else the browser's localized message. An error the author set (a server error, say) is left as it is.
clearValidation()Clear the error and warning that validate() and warning-pattern showed (a form reset does).
emitValue(commit)For subclasses: fire the value events, as a native control does on a user edit: input (bubbles, composed), then with commit also change (bubbles, stays in its tree).
idrefText(ids)For subclasses: the text of the elements an ID reference list names, resolved in the host's tree (ID references cannot cross a shadow root), joined by spaces.
select()Select all text in the input, like native.
setSelectionRange(start, end, direction)Set the text selection in the input, like native.

Events

EventDescription
inputFired on every user edit of the value.
changeFired when the user commits a change.

CSS parts

Style the inside of the component with ::part(), for example focsd-currency-field::part(label).

PartDescription
labelThe label.
fieldThe box around the input and the currency.
prefixThe currency before the number (while editing).
suffixThe currency after the number (while editing).
controlThe input.
layoutThe box around the label and the body; `data-position` is the label position.
bodyThe field and its messages.
hintThe hint.
messageThe shown message; also `error`, `warning` or `success` for its kind.
message-iconThe icon in the message.
announcerThe visually hidden status region that announces a new message.

Accessibility

  • An APG role="spinbutton" whose aria-valuetext is the formatted amount ("€1,234.50").
  • The currency name and code are part of the accessible description.
  • Typing accepts the page language's decimal and group symbols and pasted currency signs.
  • The value and form entry are a dot-decimal string with the currency's decimals ("1234.50", "100" for yen).
  • Out-of-range amounts report a formatted message ("Enter €10,000.00 or less").

Keyboard

KeyAction
Arrow Up / DownStep by step (default: the smallest unit, such as one cent)
Page Up / DownStep by 10 × step
Home / EndJump to min / max (when set)
EnterSubmits the owning form