1
1
import React , { Component , PropTypes } from 'react' ;
2
2
import shallowCompare from 'react/lib/shallowCompare' ;
3
3
import connect from 'react-redux/lib/components/connect' ;
4
+ import icepick from 'icepick' ;
4
5
5
6
import _get from '../utils/get' ;
6
7
import identity from 'lodash/identity' ;
@@ -36,12 +37,30 @@ function isChecked(props) {
36
37
return ! ! props . modelValue ;
37
38
}
38
39
40
+ function checkboxChanger ( props , eventValue ) {
41
+ const { model, modelValue } = props ;
42
+
43
+ if ( isMulti ( model ) ) {
44
+ const valueWithItem = modelValue || [ ] ;
45
+ const valueWithoutItem = ( valueWithItem || [ ] )
46
+ . filter ( item => item !== eventValue ) ;
47
+ const value = ( valueWithoutItem . length === valueWithItem . length )
48
+ ? icepick . push ( valueWithItem , eventValue )
49
+ : valueWithoutItem ;
50
+
51
+ return value ;
52
+ }
53
+
54
+ return ! modelValue ;
55
+ }
56
+
39
57
const controlPropsMap = {
40
58
default : ( props ) => controlPropsMap . text ( props ) ,
41
59
checkbox : ( props ) => ( {
42
60
...props ,
43
61
name : props . model ,
44
62
checked : isChecked ( props ) ,
63
+ updater : checkboxChanger ,
45
64
} ) ,
46
65
radio : ( props ) => ( {
47
66
...props ,
@@ -114,9 +133,7 @@ function createFieldControlComponent(control, props, options) {
114
133
}
115
134
116
135
/* eslint-disable react/prop-types */
117
- const {
118
- mapProps = options . controlPropsMap [ getControlType ( control , options ) ] ,
119
- } = props ;
136
+ const mapProps = options . controlPropsMap [ getControlType ( control , options ) ] ;
120
137
121
138
const controlProps = omit ( props , [ 'children' , 'className' ] ) ;
122
139
@@ -196,6 +213,11 @@ function createFieldClass(customControlPropsMap = {}, defaultProps = {}) {
196
213
] ) ,
197
214
parser : PropTypes . func ,
198
215
formatter : PropTypes . func ,
216
+ formatOn : PropTypes . oneOf ( [
217
+ 'change' ,
218
+ 'blur' ,
219
+ 'focus' ,
220
+ ] ) ,
199
221
updateOn : PropTypes . oneOf ( [
200
222
'change' ,
201
223
'blur' ,
@@ -213,14 +235,14 @@ function createFieldClass(customControlPropsMap = {}, defaultProps = {}) {
213
235
PropTypes . func ,
214
236
PropTypes . object ,
215
237
] ) ,
216
- mapProps : PropTypes . func ,
217
238
modelValue : PropTypes . any ,
218
239
} ;
219
240
220
241
Field . defaultProps = {
221
242
updateOn : 'change' ,
222
243
validateOn : 'change' ,
223
244
asyncValidateOn : 'blur' ,
245
+ formatOn : 'blur' ,
224
246
parser : identity ,
225
247
formatter : identity ,
226
248
changeAction : change ,
0 commit comments