Numeric Field
BsNumericField is a form field component that let users enter numeric text into an UI.
Overview
BsNumericField component mimics the HTML5 <input type="number"> behaviour. This means that you can add attributes like required, readonly, or disabled and it will react to them to give the best experience. You can also use v-model directive to create two-way data bindings on the model-value property.
Additionally, you can use keyboard UP/DOWN arrow to increment or decrement the value.
IMPORTANT
Do not use the model-value property when using v-model.
Style Variants
You can style <bs-numeric-field> to your own preference or use a style variant based on Google Material Design 2 or Material Design 3 specifications.
Default
You can style <bs-numeric-field> that follows Google Material Design 2 specifications by using floating-label property explicitly.
Filled
Use filled property explicitly to enable <bs-numeric-field> with solid fill style. And when combined with floating-label property, <bs-numeric-field> will have a style that follows the Google Material Design 3 specifications.
Outlined
Use outlined property explicitly to enable <bs-numeric-field> with outline style. And when combined with floating-label property, <bs-numeric-field> will have a style that follows the Google Material Design 3 specifications.
Filled Rounded
Combine filled property and rounded property explicitly to enable <bs-numeric-field> with rounded pill solid style.
Outlined Rounded
Combine outlined property and rounded property explicitly to enable <bs-numeric-field> with rounded pill outline style.
Action Buttons
The BsNumericField has two variants of action buttons to increment/decrement the numeric value.
Updated in v2.2.0Spin Buttons
The Spin action buttons is the default action buttons. They can be placed on the left or right side (default).
Plus-Minus Buttons
The Plus-Minus action buttons can be enabled by setting the value of action-button property to plus-minus. They can be placed on the left, right (default) or both side.
Clearable
Define the clear-button property explicitly, so that the field value can be cleared easily.
Help Text
The help-text property on <bs-numeric-field> adds an help text beneath the numeric field. And define the persistent-help-off property explicitly to make the help text visible only when the numeric field is focused.
Icons
The properties prepend-icon, prepend-icon-outer, append-icon and append-icon-outer provides the ability to add icon to <bs-numeric-field>.
Use any valid android icon name from Google Material Symbols with or without a suffix. Valid suffixes are: _outlined, _rounded, _sharp, _filled, _outlined_filled, _rounded_filled, and _sharp_filled. Suffix _filled and _outlined_filled will display the same icon style variant.
INFO
Since v2.1.0, Google Material Icons are replaced with Google Material Symbols.
Prefixes and Suffixes
The prefix and suffix properties allows you to prepend and append inline non-modifiable text before or after the input field.
Added in v2.0.10Usage Example
The following is an example that demonstrate more advanced use of the <bs-numeric-field> with form validation.
CSS Variables
As CSS technology evolves, Vue MDBootstrap introduces local CSS variables on .md-field and global CSS variables for better customization.
.md-field {
--md-field-border-width: 1px;
--md-field-border-color: #{colors.$gray-400};
--md-field-border-radius: #{vars.$text-field-border-radius};
--md-field-hover-border-color: currentColor;
--md-field-active-border-width: 2px;
--md-field-active-border-color: var(--md-field-active-indicator);
--md-field-color-bg: currentColor;
--md-field-outline-bg: transparent;
--md-field-outline-hover-bg: transparent;
--md-field-outline-focus-bg: transparent;
--md-field-outline-border-radius: var(--md-field-border-radius);
--md-field-control-height: #{vars.$text-field-height};
--md-field-label-color: currentColor;
--md-field-label-font-weight: var(--font-weight-medium);
--md-field-inline-text-font-weight: var(--font-weight-medium);
--md-field-floating-label-color: var(--md-field-label-color);
--md-field-padding-start: #{vars.$text-field-padding-start};
--md-field-padding-end: #{vars.$text-field-padding-end};
--md-field-padding-top: #{vars.$text-field-padding-top};
--md-field-padding-bottom: #{vars.$text-field-padding-bottom};
--md-field-classic-padding-top: #{vars.$text-field-classic-padding-top};
--md-field-classic-padding-bottom: #{vars.$text-field-classic-padding-bottom};
}:root {
--md-field-primary-indicator: oklch(0.458 0.23 304.441);
--md-field-accent-indicator: oklch(0.743 0.102 303.276);
--md-field-active-indicator: var(--md-field-primary-indicator);
--md-field-button-active-bg: oklch(0.154 0 89.876 / 0.25);
--md-field-button-hover-bg: oklch(0.431 0 89.876 / 0.2);
--md-field-button-hover-color: oklch(0.209 0 89.876);
--md-field-button-color: currentColor;
--md-field-disabled-opacity: 0.4;
--md-field-readonly-opacity: 0.55;
--md-caret-size: 5px;
}API Reference
TValidator
The validator configuration option has properties as described below:
| Property | Type | Description |
|---|---|---|
| validators | Record<String, Boolean> | External validator plugin validation result. |
| messages | Record<String, Boolean> | Validation message for each validation types. |
| hasError | Boolean | An indicator that tells the field value pass the validation or not. |
| dirty | Boolean | Value comes from validator plugin that indicate the field is dirty or not. |
All properties are mandatory.
NOTE
Vue MDBootstrap does not include form validation by default, we leave that up to the 3rd party form validation plugin. As of now, Vuelidate has been fully tested with our component library.
