11import { Checkbox , CheckboxGroup } from 'element-ui'
22import noop from 'lodash/noop'
33import 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'
75
8- export default {
6+ const ConnectedCheckboxGroup = {
97 props : {
108 name : {
119 type : String ,
@@ -67,25 +65,7 @@ export default {
6765 labelWidth : String ,
6866 } ,
6967
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 ] ,
8969
9070 methods : {
9171 generateOptions ( option ) {
@@ -108,13 +88,7 @@ export default {
10888 )
10989 } ,
11090
111- handleFieldBlur ( ...args ) {
112- this . touched = true
113-
114- this . handleBlur ( ...args )
115- } ,
116-
117- renderCheckboxGroup ( value , setValue ) {
91+ renderComponent ( value , setValue ) {
11892 return (
11993 < CheckboxGroup
12094 class = { this . class }
@@ -133,19 +107,6 @@ export default {
133107 )
134108 } ,
135109 } ,
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- } ,
151110}
111+
112+ export default ConnectedCheckboxGroup
0 commit comments