Toggle Field
BsToggleField is a form field component with a group of buttons with toggle capabilities, and validation. It is primarily used to visualize choices with different approach.
Overview
BsToggleField component internally uses BsToggleButton but with validation capabilities. This means the component shares the same style variants as BsToggleButton.
BsToggleField component mimics the HTML5 <input>
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. This is useful to control or maintain the model-value
property.
What are you drinking?
IMPORTANT
- The
<bs-field-toggle-field>
tag still works, but has been deprecated since v2.0.0. - Never assign a datasource to multiple
<bs-toggle-field>
. It may cause a bug or duplicate ID attribute.
TIP
Any MDBootstrap Color variants and Material Color variants can be applied to the color
property.
Checked Icon
With the help of slot icon
you can add dynamic checked icon.
Multiple Selection
BsToggleField also support multiple selection mode. Use and define the multiple
property explicitly to enable multiple selection mode.
Style Variants
You can style the <bs-toggle-field>
component to your own preference or use a style variant based on Google Material Design 3 specifications. Example below show various built-in style variants and demonstrate how to put an icon inside the <bs-toggle-field>
and change the icon dynamically like a segmented buttons behaves.
How is the weather today?
Combination
How is the weather today?
INFO
Since Vue MDBootstrap v2.1.0, Google Material Icons are replaced with Google Material Symbols.
Help Text
The help-text
property on <bs-toggle-field>
adds the provided string beneath the Toggle Field. And sets the persistent-help-text
property to false
to make the help text visible when the Toggle Field is focused or hovered.
Persistent help text
Non-persistent help text
Usage Example
The following is an example that demonstrate more advanced use of the <bs-toggle-field>
with form validation.
CSS Variables
The component css variables inherited from BsButton css variables.
Added since v2.0.0API Reference
TInputOptionItem
The Input item has properties as described below:
Property | Type | Description |
---|---|---|
value required | String /Number /Boolean | The item value. |
label required | String | The item label. |
id | String | Html <input> element ID. |
name | String | Html <input> element name. It is used when multiple is true . |
disabled | Boolean | Html <input> element state. |
readonly | Boolean | Html <input> element state. |
icon | String | The icon to display inside the button. Updated on v2.1.0 Use any valid android icon name from Google Material Symbols with or without a suffix. Valid suffixes are: iconVariant property. |
iconFlip | String | Flip the icon. Valid values are: horizontal , vertical , both . |
iconPulse | Boolean | Apply pulse animation to the icon. |
iconSize | Number | Render the icon at predefined size in pixel. |
iconSpin | Boolean | Apply spin animation to the icon. |
iconRotation | Number | Rotate the icon. Valid values are: 90 , 180 , 270 . |
iconVariant | String | Use predefined icon style variant. Valid values are: outlined , rounded , sharp , filled , outlined_filled , rounded_filled , and sharp_filled . v2.1.0 |
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.