@@ -30,20 +30,28 @@ export default {
30
30
``` html
31
31
<template >
32
32
<div >
33
- <b-form-fieldset id =" fieldset2"
33
+ <b-form-group id =" fieldset2"
34
34
:label =" label"
35
35
label-for =" checkboxes2"
36
36
:description =" desc"
37
37
:state =" state"
38
38
:feedback =" feedback"
39
39
>
40
40
<div role =" group" id =" checkboxes2" >
41
- <b-form-checkbox v-model =" selected" name =" flavour" value =" orange" >Orange</b-form-checkbox >
42
- <b-form-checkbox v-model =" selected" name =" flavour" value =" apple" >Apple</b-form-checkbox >
43
- <b-form-checkbox v-model =" selected" name =" flavour" value =" pineapple" >Pineapple</b-form-checkbox >
44
- <b-form-checkbox v-model =" selected" name =" flavour" value =" grape" >Grape</b-form-checkbox >
41
+ <b-form-checkbox v-model =" selected" :state =" state" name =" flavour" value =" orange" >
42
+ Orange
43
+ </b-form-checkbox >
44
+ <b-form-checkbox v-model =" selected" :state =" state" name =" flavour" value =" apple" >
45
+ Apple
46
+ </b-form-checkbox >
47
+ <b-form-checkbox v-model =" selected" :state =" state" name =" flavour" value =" pineapple" >
48
+ Pineapple
49
+ </b-form-checkbox >
50
+ <b-form-checkbox v-model =" selected" :state =" state" name =" flavour" value =" grape" >
51
+ Grape
52
+ </b-form-checkbox >
45
53
</div >
46
- </b-form-fieldset >
54
+ </b-form-group >
47
55
<hr >
48
56
<div >Selected: <strong >{{ selected }}</strong ></div >
49
57
</div >
@@ -58,20 +66,20 @@ export default {
58
66
},
59
67
computed: {
60
68
feedback () {
61
- if (this .selected .length > 2 ) {
62
- return " Don't be greedy!" ;
63
- } else if (this .selected .length === 1 ) {
64
- return ' Select one more... ' ;
65
- }
66
- return ' ' ;
69
+ if (this .selected .length > 2 ) {
70
+ return " Don't be greedy!" ;
71
+ } else if (this .selected .length === 1 ) {
72
+ return " Select one more"
73
+ }
74
+ return ' ' ;
67
75
},
68
76
state () {
69
77
if (this .selected .length > 2 ) {
70
- return ' danger ' ;
78
+ return ' invalid ' ;
71
79
} else if (this .selected .length === 2 ) {
72
- return ' success ' ;
80
+ return ' valid ' ;
73
81
} else if (this .selected .length === 1 ) {
74
- return ' warning ' ;
82
+ return ' injvalid ' ;
75
83
}
76
84
return ' ' ;
77
85
}
@@ -82,11 +90,10 @@ export default {
82
90
<!-- form-checkbox-2.vue -->
83
91
```
84
92
85
- ### Inline and Stacked checkboxes
93
+ ## Inline and Stacked checkboxes
86
94
` <b-form-checbox> ` components render as inline elements by default. Add a parent
87
95
with class ` .custom-controls-stacked ` to ensure each form control is on a separate line.
88
96
89
- ** Example 3: Inline & Stacked checkboxes:**
90
97
``` html
91
98
<template >
92
99
<div >
@@ -119,7 +126,7 @@ export default {
119
126
<!-- form-checkbox-3.vue -->
120
127
```
121
128
122
- ### Value(s)
129
+ ## Value(s)
123
130
By default, ` <b-form-checkbox> ` value will be ` true ` when checked and ` false ` when unchecked.
124
131
You can customize the checked and unchecked values by specifying the ` value ` and ` unchecked-value `
125
132
properties.
@@ -133,20 +140,20 @@ be returned in the `v-model` bound array. You should provide unique values for e
133
140
checkbox's ` value ` prop.
134
141
135
142
136
- #### Multiple checkboxes and accessibility
143
+ ### Multiple checkboxes and accessibility
137
144
When binding multiple checkboxes together, you should set the ` name ` prop to the same value for
138
145
all checkboxes in the group, as well as wrap the group in a ` <div> ` (or other block element)
139
146
which has the aria attribute ` role="group" ` . This will inform users of assitive technologies
140
147
that the checkboxes are related.
141
148
142
- When placing the group of checkboxes inside a ` <b-form-fieldset > ` , set a unique ` id ` on the
149
+ When placing the group of checkboxes inside a ` <b-form-groupt > ` , set a unique ` id ` on the
143
150
element with ` role="group" ` and set the ` label-for ` prop of the ` <b-form-fieldet> ` to
144
151
this ` id ` value (see ** Example 2** above). Whenever using grouped checkboxes, it is
145
152
recommended that they be placed in a ` <b-form-fieldset> ` component to associate a ` <label> `
146
153
with the entire group of checkboxes.
147
154
148
155
149
- ### Button style checkboxes
156
+ ## Button style checkboxes
150
157
Render a checkbox with the look of a button by setting the prop ` button ` . Change the button variant by
151
158
setting the ` button-variant ` prop to one of the standard Bootstrap button variants (see
152
159
[ ` <b-button> ` ] ( ./button ) for supported variants). The default ` button-variant ` is ` secondary ` .
@@ -157,7 +164,6 @@ and add the attribute `data-toggle="buttons"` to get the proper Bootstrap CSS st
157
164
Button style checkboxes will have the class ` .active ` automatically applied to the label
158
165
when they are in the checked state.
159
166
160
- ** Example 4: Button style checkboxes:**
161
167
``` html
162
168
<template >
163
169
<div >
@@ -200,16 +206,24 @@ export default {
200
206
<!-- form-checkbox-4.vue -->
201
207
```
202
208
203
- ### Contextual states
204
- To apply contextual state colors to ` <b-form-checkbox> ` , it must be wrapped in
205
- a ` <b-form-fieldset> ` component (which has the ` state ` prop set to the state you
206
- would like), or wrapped in another element - such as a ` <div> ` - which has one
207
- of the standard Bootstrap V4 ` .has-* ` state class applied.
209
+ ## Contextual states
210
+ Bootstrap includes validation styles for ` valid ` and ` invalid ` states
211
+ on most form controls.
208
212
209
- ** Note:** Contextual states are not supported when ` button ` is set.
213
+ Generally speaking, you’ll want to use a particular state for specific types of feedback:
214
+ - ` 'invalid' ` is great for when there’s a blocking or required field. A user must fill in
215
+ this field properly to submit the form.
216
+ - ` 'valid' ` is ideal for situations when you have per-field validation throughout a form
217
+ and want to encourage a user through the rest of the fields.
218
+ - ` null ` Displays no validation state
210
219
220
+ To apply one of the contextual state icons on ` <b-form-checkbox> ` , set the ` state ` prop
221
+ to ` 'invalid' ` , ` 'valid' ` , or ` null ` .
211
222
212
- ### Indeterminate (tri-state) support
223
+ ** Note:** Contextual states are not supported when ` button ` mode is set.
224
+
225
+
226
+ ## Indeterminate (tri-state) support
213
227
Normally checkbox inputs can only have two states: ` checked ` or ` unchecked ` . They can
214
228
have any value, but they either submit that value (checked) or don't (unchecked) with
215
229
a form submission (although Bootstrap-Vue allows a value for the ` unchecked ` state)
@@ -228,7 +242,7 @@ The `indeterminate` prop can be synced to the checkboxe's state by v-binding the
228
242
229
243
** Note:** indeterminate is not supported when ` button ` is set.
230
244
231
- ** Example 5: Single Indeterminate checkbox:**
245
+ ** Single Indeterminate checkbox:**
232
246
``` html
233
247
<template >
234
248
<div >
@@ -261,7 +275,7 @@ export default {
261
275
<!-- form-checkbox-5.vue -->
262
276
```
263
277
264
- ** Example 6: Indeterminate checkbox use-case:**
278
+ ** Indeterminate checkbox use-case:**
265
279
``` html
266
280
<template >
267
281
<b-card >
@@ -282,6 +296,7 @@ export default {
282
296
v-model =" selected"
283
297
name =" flavs"
284
298
:value =" flavour"
299
+ :key =" flavour"
285
300
>{{ flavour }}</b-form-checkbox >
286
301
</div >
287
302
<p aria-live =" polite" >Selected: <strong >{{ selected }}</strong ></p >
@@ -322,20 +337,22 @@ export default {
322
337
<!-- form-checkbox-6.vue -->
323
338
```
324
339
325
- #### Indeterminate state and accessibility
340
+ ** Note:** indeterminate is not supported in ` button ` mode.
341
+
342
+ ### Indeterminate state and accessibility
326
343
Not all screen readers will convey the indeterminate state to screen reader users.
327
- So it is recommended to provide some form of textual feedback to the user (possibly
344
+ So it is recommended to provide some form of textual feedback to the user (possibly
328
345
by via the ` .sr-only ` class) if the indeterminate state has special contextual
329
346
meaning in your application.
330
347
331
348
332
- ### Non custom check inputs
349
+ ## Non custom check inputs
333
350
You can have ` b-form-checkbox ` render a browser native chechbox input by setting the ` plain ` prop.
334
351
335
352
** Note:** The ` plain ` prop has no effect with ` button ` is set.
336
353
337
354
### See also
338
- - [ ` <b-form-fieldset > ` ] ( ./form-fieldset )
355
+ - [ ` <b-form-group > ` ] ( ./form-group )
339
356
- [ ` <b-button-group> ` ] ( ./button-group )
340
357
- [ ` <b-button> ` ] ( ./button )
341
358
0 commit comments