Text Field
BsTextField is a component that let users enter text into an UI.
Overview
BsTextField component mimics the HTML5 <input type="text">
element. 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.
IMPORTANT
Do not use the model-value
property when using v-model
.
Style Variants
You can style <bs-text-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-text-field>
that follows Google Material Design 2 specifications by using floating-label
property explicitly.
Filled
Use filled
property explicitly to enable <bs-text-field>
with solid fill style. And when combined with floating-label
property, <bs-text-field>
will have a style that follows the Google Material Design 3 specifications.
Outlined
Use outlined
property explicitly to enable <bs-text-field>
with outline style. And when combined with floating-label
property, <bs-text-field>
will have a style that follows the Google Material Design 3 specifications.
Rounded Filled
Combine filled
property and rounded
property explicitly to enable <bs-text-field>
with rounded pill solid style.
Rounded Outlined
Combine outlined
property and rounded
property explicitly to enable <bs-text-field>
with rounded pill outline style.
Browser Autocomplete
The autocomplete
property gives you the option to enable browser to predict the user input.
Datalist Support
Datalist is a native HTML tag of <datalist>
that contains a list of <option>
tags. By assigning an ID to the datalist tag, the list can be references from a text field by defining the datalist
property explicitly. This give the text field the behavior of a combobox or auto-complete, allowing existing values to be chosen, or new values to be entered.
INFO
- Datalists work in conjunction with the browser's built in auto-complete, displaying datalist options first, followed by auto-complete options.
- Datalists cannot be applied to input fields with type
password
, orrange
. - Not all browsers fully support
<datalist>
and implementations can be buggy. It is recommended that datalists be treated as an enhancement and not be relied upon at this time. Check Can I Use for full support details on all browsers.
Clearable
Define the clear-button
property explicitly, so that the field value can be cleared easily.
Help Text
The help-text
property on <bs-text-field>
adds an help text beneath the text field. And sets the persistent-help-text
property to false
will make the help text visible only when the text 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-text-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 Vue MDBootstrap 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 since v2.0.10Usage Example
The following is an example that demonstrate more advanced use of the <bs-text-field>
with form validation.
CSS Variables
Updated on v2.0.10--md-field-active-border-color: rgb(var(--md-field-active-indicator));
--md-field-active-border-width: 2px;
--md-field-color-bg: currentColor;
--md-field-border-color: currentColor;
--md-field-border-width: 1px;
--md-field-control-height: 3.5rem;
--md-field-floating-label-color: var(--md-field-label-color);
--md-field-label-color: currentColor;
--md-field-padding-start: 1rem;
--md-field-padding-end: 1rem;
--md-field-padding-top: 1.625rem;
--md-field-padding-bottom: 0.375rem;
--md-field-inline-text-font-weight: 500;
// global css variables
--md-field-primary-indicator-rgb: 98, 0, 238;
--md-field-primary-indicator: rgb(var(--md-field-primary-indicator-rgb));
--md-field-accent-indicator-rgb: 185,156,225;
--md-field-accent-indicator: rgb(var(--md-field-accent-indicator-rgb));
--md-field-active-indicator: var(--md-field-primary-indicator-rgb);
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 ,String> | 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.