Skip to content

Commit fd3f85d

Browse files
author
Pooya Parsa
committed
Use vue 2.2.x custom models bootstrap-vue#134
1 parent 44fd9b9 commit fd3f85d

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

components/form-checkbox.vue

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
type="checkbox"
66
:id="id"
77
:name="name"
8-
:value="_value"
8+
:value="value"
99
:disabled="disabled"
10-
@change="change($event.target.checked)"
11-
:checked="localChecked"
12-
10+
:checked="checked===value"
11+
@change="$emit('change',$event.target.checked?value:uncheckedValue)"
1312
>
1413
<span class="custom-control-indicator" v-if="custom"></span>
1514
<span :class="[custom?'custom-control-description':null]"><slot></slot></span>
@@ -22,11 +21,12 @@
2221
export default {
2322
data() {
2423
return {
25-
localChecked: this.checked
26-
};
24+
25+
}
2726
},
28-
mounted() {
29-
this.change(this.localChecked);
27+
model: {
28+
prop: 'checked',
29+
event: 'change'
3030
},
3131
computed: {
3232
inputState() {
@@ -42,14 +42,16 @@
4242
type: String,
4343
default: null
4444
},
45-
_value: {
45+
value: {
4646
default: true
4747
},
48-
disabled: {
49-
type: Boolean,
48+
uncheckedValue: {
5049
default: false
5150
},
5251
checked: {
52+
default: true
53+
},
54+
disabled: {
5355
type: Boolean,
5456
default: false
5557
},
@@ -61,13 +63,6 @@
6163
type: Boolean,
6264
default: true
6365
}
64-
},
65-
methods: {
66-
change(checked) {
67-
this.localChecked = checked;
68-
this.$emit('change', checked);
69-
this.$emit('input', checked ? this._value : undefined);
70-
}
7166
}
7267
};
7368

docs/data/site.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default {
2222
{title: 'Form Inputs'},
2323
{title: 'Form Fieldset'},
2424
{title: 'Form Radio'},
25-
{title: 'Form Checkbox'},
25+
{title: 'Form Checkbox', new: true},
2626
{title: 'Form Select'},
2727
{title: 'Modals', experimental: true},
2828
{title: 'Nav'},

docs/pages/docs/components/form-checkbox.vue

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@
55
</template>
66

77
<template slot="description">
8-
This component uses a special <code>_value</code> Property to keep compatible with <code>v-model</code>
9-
directive.
8+
109
</template>
1110

1211
<template slot="demo">
1312

14-
<b-form-checkbox v-model="check1" _value="Option1" checked>
15-
CheckBox Default
13+
<b-form-checkbox v-model="state" value="accepted" unchecked-value="not_accepted">
14+
I accept terms and use
1615
</b-form-checkbox>
1716

18-
<div>Value: {{check1}}</div>
17+
<div>State: <strong>{{state}}</strong></div>
1918

2019
</template>
2120

2221
<template slot="usage">
23-
&lt;b-form-checkbox v-model=&quot;check1&quot; _value=&quot;Option1&quot; checked&gt;
24-
CheckBox Default
22+
&lt;b-form-checkbox v-model=&quot;check1&quot; value=&quot;Option1&quot;
23+
Tick me
2524
&lt;/b-form-checkbox&gt;
2625
</template>
2726

@@ -54,7 +53,7 @@ export default {
5453
}
5554
]
5655
},
57-
check1: ''
56+
state: 'please_accept'
5857
};
5958
}
6059
};

0 commit comments

Comments
 (0)