Money Field
Collect monetary values from users with built-in currency formatting and validation.
Anchor to propertiesProperties
- Anchor to autocompleteautocompletestring
A hint as to the intended content of the field.
When set to
on
(the default), this property indicates that the field should support autofill, but you do not have any more semantic information on the intended contents.When set to
off
, you are indicating that this field contains sensitive information, or contents that are never saved, like one-time codes.Alternatively, you can provide value which describes the specific data you would like to be entered into this field during autofill.
- Anchor to defaultValuedefaultValuestring
The default value for the field.
- Anchor to detailsdetailsstring
Additional text to provide context or guidance for the field. This text is displayed along with the field and its label to offer more information or instructions to the user.
This will also be exposed to screen reader users.
- Anchor to disableddisabledboolean
Disables the field, disallowing any interaction.
- Anchor to errorerrorstring
Indicate an error to the user. The field will be given a specific stylistic treatment to communicate problems that have to be resolved immediately.
- string
A unique identifier for the element.
- Anchor to labellabelstring
Content to use as the field label.
- Anchor to labelAccessibilityVisibilitylabelAccessibilityVisibility"visible" | "exclusive"
Changes the visibility of the component's label.
visible
: the label is visible to all users.exclusive
: the label is visually hidden but remains in the accessibility tree.
- number
The highest decimal or integer to be accepted for the field. When used with
step
the value will round down to the max number.Note: a user will still be able to use the keyboard to input a number higher than the max. It is up to the developer to add appropriate validation.
- number
The lowest decimal or integer to be accepted for the field. When used with
step
the value will round up to the min number.Note: a user will still be able to use the keyboard to input a number lower than the min. It is up to the developer to add appropriate validation.
- Anchor to namenamestring
An identifier for the field that is unique within the nearest containing form.
- Anchor to placeholderplaceholderstring
A short hint that describes the expected value of the field.
- Anchor to readOnlyreadOnlyboolean
The field cannot be edited by the user. It is focusable will be announced by screen readers.
- Anchor to requiredrequiredboolean
Whether the field needs a value. This requirement adds semantic value to the field, but it will not cause an error to appear automatically. If you want to present an error when this field is empty, you can do so with the
error
property.- Anchor to stepstepnumber
The amount the value can increase or decrease by. This can be an integer or decimal. If a
max
ormin
is specified withstep
when increasing/decreasing the value via the buttons, the final value will always round to themax
ormin
rather than the closest valid amount.- Anchor to valuevaluestring
The current value for the field. If omitted, the field will be empty.
MoneyField
- __@internals$4@5319
ElementInternals
- adoptedCallback
() => void
- attributeChangedCallback
(name: string) => void
- autocomplete
A hint as to the intended content of the field. When set to `on` (the default), this property indicates that the field should support autofill, but you do not have any more semantic information on the intended contents. When set to `off`, you are indicating that this field contains sensitive information, or contents that are never saved, like one-time codes. Alternatively, you can provide value which describes the specific data you would like to be entered into this field during autofill.
string
- click
Like the standard `element.click()`, but you can influence the behavior with a `sourceEvent`. For example, if the `sourceEvent` was a middle click, or has particular keys held down, components will attempt to produce the desired behavior on links, such as opening the page in the background tab.
({ sourceEvent }?: ClickOptions) => void
- connectedCallback
() => void
- defaultValue
The default value for the field.
string
- details
Additional text to provide context or guidance for the field. This text is displayed along with the field and its label to offer more information or instructions to the user. This will also be exposed to screen reader users.
string
- disabled
Disables the field, disallowing any interaction.
boolean
- disconnectedCallback
() => void
- error
Indicate an error to the user. The field will be given a specific stylistic treatment to communicate problems that have to be resolved immediately.
string
- formResetCallback
() => void
- getAttribute
Global keyboard event handlers for things like key bindings typically ignore keystrokes originating from within input elements. Unfortunately, these never account for a Custom Element being the input element. To fix this, we spoof getAttribute & hasAttribute to make a PreactFieldElement appear as a contentEditable "input" when it contains a focused input element.
(qualifiedName: string) => string
- hasAttribute
(qualifiedName: string) => boolean
- id
A unique identifier for the element.
string
- isContentEditable
Checks if the shadow tree contains a focused input (input, textarea, select, <x contentEditable>). Note: this does _not_ return true for focussed non-field form elements like buttons.
boolean
- label
Content to use as the field label.
string
- labelAccessibilityVisibility
Changes the visibility of the component's label. - `visible`: the label is visible to all users. - `exclusive`: the label is visually hidden but remains in the accessibility tree.
"visible" | "exclusive"
- max
The highest decimal or integer to be accepted for the field. When used with `step` the value will round down to the max number. Note: a user will still be able to use the keyboard to input a number higher than the max. It is up to the developer to add appropriate validation.
number
- min
The lowest decimal or integer to be accepted for the field. When used with `step` the value will round up to the min number. Note: a user will still be able to use the keyboard to input a number lower than the min. It is up to the developer to add appropriate validation.
number
- name
An identifier for the field that is unique within the nearest containing form.
string
- placeholder
A short hint that describes the expected value of the field.
string
- queueRender
Queue a run of the render function. You shouldn't need to call this manually - it should be handled by changes to @property values.
() => void
- readOnly
The field cannot be edited by the user. It is focusable will be announced by screen readers.
boolean
- required
Whether the field needs a value. This requirement adds semantic value to the field, but it will not cause an error to appear automatically. If you want to present an error when this field is empty, you can do so with the `error` property.
boolean
- setAttribute
(name: string, value: string) => void
- step
The amount the value can increase or decrease by. This can be an integer or decimal. If a `max` or `min` is specified with `step` when increasing/decreasing the value via the buttons, the final value will always round to the `max` or `min` rather than the closest valid amount.
number
- value
The current value for the field. If omitted, the field will be empty.
string
declare class MoneyField
extends PreactFieldElement<MoneyFieldProps['autocomplete']>
implements MoneyFieldProps
{
accessor max: MoneyFieldProps['max'];
accessor min: MoneyFieldProps['min'];
accessor step: MoneyFieldProps['step'];
get value(): MoneyFieldProps['value'];
set value(value: MoneyFieldProps['value']);
constructor();
}
ClickOptions
- sourceEvent
The event you want to influence the synthetic click.
ActivationEventEsque
export interface ClickOptions {
/**
* The event you want to influence the synthetic click.
*/
sourceEvent?: ActivationEventEsque;
}
ActivationEventEsque
- button
number
- ctrlKey
boolean
- metaKey
boolean
- shiftKey
boolean
export interface ActivationEventEsque {
shiftKey: boolean;
metaKey: boolean;
ctrlKey: boolean;
button: number;
}
Anchor to eventsEvents
Learn more about registering events.
- Anchor to blurblurCallbackEventListener<'input'>
- Anchor to changechangeCallbackEventListener<'input'>
- Anchor to focusfocusCallbackEventListener<'input'>
- Anchor to inputinputCallbackEventListener<'input'>
MoneyFieldEvents
- blur
CallbackEventListener<'input'>
- change
CallbackEventListener<'input'>
- focus
CallbackEventListener<'input'>
- input
CallbackEventListener<'input'>
export interface MoneyFieldEvents {
change: CallbackEventListener<'input'>;
input: CallbackEventListener<'input'>;
blur: CallbackEventListener<'input'>;
focus: CallbackEventListener<'input'>;
}
CallbackEventListener
(EventListener & {
(event: CallbackEvent<T>): void;
}) | null
CallbackEvent
Event & {
currentTarget: HTMLElementTagNameMap[T];
}
Code
examples
Code
<s-money-field label="Regional Price" placeholder="99.99" currencyCode="EUR" details="Recommended price for the European market" ></s-money-field>
<!DOCTYPE html><html><head><style>html, body {height:100%} body {box-sizing: border-box; margin: 0; padding:0.5rem; display: grid; place-items: center; gap: 0.5rem;}</style><script src="https://cdn.shopify.com/shopifycloud/app-bridge-ui-experimental.js"></script></head><body><s-money-field label="Regional Price" placeholder="99.99" currencyCode="EUR" details="Recommended price for the European market" ></s-money-field> </body></html>