Skip to content

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.

Updated on v2.0.0
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.

Added since v2.0.1

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.

Updated on v2.0.1
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
Select a wheather for today
Non-persistent help text

Usage Example

The following is an example that demonstrate more advanced use of the <bs-toggle-field> with form validation.

By submitting your information, you agree to our Term & Conditions and Privacy Policy.

CSS Variables

The component css variables inherited from BsButton css variables.

Added since v2.0.0

API Reference

TInputOptionItem

The Input item has properties as described below:

PropertyTypeDescription
value requiredString/Number/BooleanThe item value.
label requiredStringThe item label.
idStringHtml <input> element ID.
nameStringHtml <input> element name. It is used when multiple is true.
disabledBooleanHtml <input> element state.
readonlyBooleanHtml <input> element state.
iconString
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: _outlined, _rounded, _sharp, _filled, _outlined_filled, _rounded_filled, and _sharp_filled.

Suffix will take precedence over iconVariant property.
iconFlipStringFlip the icon. Valid values are: horizontal, vertical, both.
iconPulseBooleanApply pulse animation to the icon.
iconSizeNumberRender the icon at predefined size in pixel.
iconSpinBooleanApply spin animation to the icon.
iconRotationNumberRotate the icon. Valid values are: 90, 180, 270.
iconVariantStringUse 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:

PropertyTypeDescription
validatorsRecord<String,Boolean>External validator plugin validation result.
messagesRecord<String,String>Validation message for each validation types.
hasErrorBooleanAn indicator that tells the field value pass the validation or not.
dirtyBooleanValue 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.

Released under the BSD-3-Clause License.