1
1
import { Checkbox , CheckboxGroup } from 'element-ui'
2
2
import noop from 'lodash/noop'
3
3
import isNil from 'lodash/isNil'
4
- import castArray from 'lodash/castArray'
5
- import resolveRegisterFormComponent from './utils/resolveRegisterFormComponent'
6
- import FormItem from './ConnectedFormItem'
4
+ import { ConnectedCheckboxGroupMixin } from './mixins/ConnectedControl'
7
5
8
- export default {
6
+ const ConnectedCheckboxGroup = {
9
7
props : {
10
8
name : {
11
9
type : String ,
@@ -67,25 +65,7 @@ export default {
67
65
labelWidth : String ,
68
66
} ,
69
67
70
- data ( ) {
71
- const $registerFormComponent = resolveRegisterFormComponent ( this )
72
-
73
- let initialValue = this . value
74
-
75
- // If there is no defined "value" inside props — use an empty array
76
- if ( isNil ( initialValue ) ) {
77
- initialValue = [ ]
78
- } else if ( ! Array . isArray ( initialValue ) ) {
79
- // If there is a non-null value, but it is not an array — cast it to an array
80
- initialValue = castArray ( initialValue )
81
- }
82
-
83
- return $registerFormComponent ( this . name , initialValue , this . validators , this . asyncValidators )
84
- } ,
85
-
86
- destroyed ( ) {
87
- this . cleanFormValue ( )
88
- } ,
68
+ mixins : [ ConnectedCheckboxGroupMixin ] ,
89
69
90
70
methods : {
91
71
generateOptions ( option ) {
@@ -108,13 +88,7 @@ export default {
108
88
)
109
89
} ,
110
90
111
- handleFieldBlur ( ...args ) {
112
- this . touched = true
113
-
114
- this . handleBlur ( ...args )
115
- } ,
116
-
117
- renderCheckboxGroup ( value , setValue ) {
91
+ renderComponent ( value , setValue ) {
118
92
return (
119
93
< CheckboxGroup
120
94
class = { this . class }
@@ -133,19 +107,6 @@ export default {
133
107
)
134
108
} ,
135
109
} ,
136
-
137
- render ( ) {
138
- const [ value , setValue , error ] = this . useState ( )
139
- const fieldError = this . touched ? error : undefined
140
-
141
- if ( this . formItem ) {
142
- return (
143
- < FormItem label = { this . label || this . name } label-width = { this . labelWidth } error = { fieldError } >
144
- { this . renderCheckboxGroup ( value , setValue ) }
145
- </ FormItem >
146
- )
147
- }
148
-
149
- return this . renderCheckboxGroup ( value , setValue )
150
- } ,
151
110
}
111
+
112
+ export default ConnectedCheckboxGroup
0 commit comments