1
- import { defineComponent , h } from 'vue'
1
+ import { computed , defineComponent , h } from 'vue'
2
2
3
3
import { CButton } from '../button'
4
4
import { CFormControlValidation } from './CFormControlValidation'
5
5
import { CFormLabel } from './CFormLabel'
6
+ import { any } from 'vue-types'
6
7
7
8
const CFormCheck = defineComponent ( {
8
9
name : 'CFormCheck' ,
@@ -94,6 +95,10 @@ const CFormCheck = defineComponent({
94
95
* Set component validation state to valid.
95
96
*/
96
97
valid : Boolean ,
98
+ /**
99
+ * The value attribute of component.
100
+ */
101
+ value : String ,
97
102
} ,
98
103
emits : [
99
104
/**
@@ -107,9 +112,9 @@ const CFormCheck = defineComponent({
107
112
] ,
108
113
setup ( props , { attrs, emit, slots } ) {
109
114
const handleChange = ( event : InputEvent ) => {
110
- const target = event . target as HTMLInputElement
115
+ console . log ( event )
111
116
emit ( 'change' , event )
112
- emit ( 'update:modelValue' , target . checked )
117
+ emit ( 'update:modelValue' , ( event . target as HTMLInputElement ) . value )
113
118
}
114
119
115
120
const className = [
@@ -132,15 +137,18 @@ const CFormCheck = defineComponent({
132
137
} ,
133
138
]
134
139
140
+ const isChecked = computed ( ( ) => props . modelValue == props . value )
141
+
135
142
const formControl = ( ) => {
136
143
return h ( 'input' , {
137
144
...attrs ,
138
- ...( props . modelValue && { checked : props . modelValue } ) ,
145
+ ...( props . modelValue && { checked : isChecked . value } ) ,
139
146
class : inputClassName ,
140
147
id : props . id ,
141
148
indeterminate : props . indeterminate ,
142
149
onChange : ( event : InputEvent ) => handleChange ( event ) ,
143
150
type : props . type ,
151
+ value : props . value ,
144
152
} )
145
153
}
146
154
0 commit comments