Skip to content

Currency Input

Currency input with selectable currency code and formatting (thousand separators, fixed decimals, symbol/code display).

Basic Usage

vue
<template>
  <spr-input-currency id="input-currency-basic" v-model="inputModel" label="Input Currenct" />
</template>

<script setup lang="ts">
import { ref } from 'vue';

const inputModel = ref('');
</script>

Active State

vue
<template>
  <spr-input-currency id="input-currency-active-state" v-model="inputModel" label="Input Currenct" active />
</template>

<script setup lang="ts">
import { ref } from 'vue';

const inputModel = ref('');
</script>

Error State

vue
<template>
  <spr-input-currency id="input-currency-error-state" v-model="inputModel" label="Input Currenct" error>
    <template #icon>
      <Icon icon="ph:warning-circle-fill" />
    </template>
  </spr-input-currency>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const inputModel = ref('');
</script>

Disabled State

vue
<template>
  <spr-input-currency id="input-currency-disabled-state" v-model="inputModel" label="Input Currenct" disabled />
</template>

<script setup lang="ts">
import { ref } from 'vue';

const inputModel = ref('');
</script>

Disabled Country Currency

vue
<template>
  <spr-input-currency
    id="input-currency-disabled-country-currency"
    v-model="inputModel"
    label="Input Currenct"
    disabled-country-currency
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';

const inputModel = ref('');
</script>

Use Currency Code or Symbol

The default of the currency component is to display the currency code (e.g., USD, EUR). You can switch to display the currency symbol (e.g., $, €) by setting the :display-as-code prop to false.

vue
<template>
  <spr-input-currency
    id="input-currency-code-or-symbol-1"
    v-model="inputModel"
    label="Input Currenct"
    :display-as-code="true"
  />

  <spr-input-currency
    id="input-currency-code-or-symbol-2"
    v-model="inputModel"
    label="Input Currenct"
    :display-as-code="false"
  />
</template>

<script setup lang="ts">
import { ref } from 'vue';

const inputModel = ref('');
</script>

Get Selected Currency Meta

Model Output:

Selected Currency:

Selected Symbol:

Raw Value:

vue
<template>
  <spr-input-currency
    id="input-currency-selected-currency"
    v-model="inputModel"
    label="Input Currenct"
    @get-selected-currency-meta="handleSelectedCurrencyMeta"
  />

  <div class="spr-bg-blue-100 spr-p-4">
    <p>Model Output: {{ inputModel }}</p>
    <p>Selected Currency: {{ selectedCurrency }}</p>
    <p>Selected Symbol: {{ selectedSymbol }}</p>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const inputModel = ref('');
const selectedCurrency = ref('');
const selectedSymbol = ref('');

const handleSelectedCurrencyMeta = (val: { currency: string; symbol: string }) => {
  selectedCurrency.value = val.currency;
  selectedSymbol.value = val.symbol;
};
</script>

Pre-Selected Currency

vue
<template>
  <spr-input-currency v-model="inputModel" label="Input Currenct" pre-selected-currency="USD" />
</template>

API Reference

NameDescriptionTypeDefault
idThe unique id for the component.String''
v-modelThe raw (possibly unformatted while typing) currency string value.String''
placeholderPlaceholder text displayed when the input is empty.String'0.00'
pre-selected-currencyInitial ISO 4217 currency code (e.g., USD, EUR). Determines initial selector value.String'PHP'
disabledDisables the entire currency input (including currency selector).Booleanfalse
disabled-country-currencyDisables only the currency selector while keeping the text field interactive.Booleanfalse
auto-formatAutomatically applies thousand separators (and limits decimals) on blur and while typing (where valid).Booleanfalse
max-decimalsMaximum number of fractional digits preserved when formatting.Number2
min-decimalsMinimum number of fractional digits (currently not padded automatically if you removed padding logic).Number2
display-as-codeWhen true shows currency code (e.g., USD); when false shows symbol (or code if symbol ambiguous).Booleantrue

For additional shared props, events, slots, and behavior inherited from the base input component, please refer to the Input Component API Reference.

Events

EventPayloadDescription
@update:model-valueStringEmitted whenever the bound input value changes (two-way binding).
@get-selected-currency-meta{ currency: String; symbol: String; numericValue: Number | null; rawValue: String | null }Emitted after selecting a currency and on blur. Includes code, symbol (or code if ambiguous), numericValue (parsed float) and rawValue (canonical unformatted string).
@get-currency-errorsArray<{ title: String; message: String }>Validation or parsing errors encountered during input normalization.
@get-numeric-valueNumberParsed numeric value (group separators stripped) emitted on mount (if initial value) and blur.