@@ -12,7 +12,7 @@ import omit from '../utils/omit';
12
12
import actionTypes from '../action-types' ;
13
13
import debounce from '../utils/debounce' ;
14
14
15
- import _getValue from '../utils/get-value' ;
15
+ import _getValue , { getCheckboxValue } from '../utils/get-value' ;
16
16
import getValidity from '../utils/get-validity' ;
17
17
import invertValidity from '../utils/invert-validity' ;
18
18
import getFieldFromState from '../utils/get-field-from-state' ;
@@ -33,21 +33,6 @@ const findDOMNode = !isNative
33
33
34
34
const disallowedProps = [ 'changeAction' , 'getFieldFromState' , 'store' ] ;
35
35
36
- function getToggleValue ( props ) {
37
- const { modelValue, controlProps } = props ;
38
-
39
- switch ( controlProps . type ) {
40
- case 'checkbox' :
41
- return typeof controlProps . value !== 'undefined'
42
- ? controlProps . value
43
- : ! modelValue ; // simple checkbox
44
-
45
- case 'radio' :
46
- default :
47
- return controlProps . value ;
48
- }
49
- }
50
-
51
36
function mergeOrSetErrors ( model , errors , options ) {
52
37
return actions . setErrors ( model , errors , {
53
38
merge : isPlainObject ( errors ) ,
@@ -223,20 +208,12 @@ function createControlClass(s = defaultStrategy) {
223
208
}
224
209
225
210
getChangeAction ( event ) {
226
- const {
227
- model,
228
- modelValue,
229
- changeAction,
230
- getValue,
231
- } = this . props ;
232
- const value = this . isToggle ( )
233
- ? getToggleValue ( this . props )
234
- : event ;
235
-
236
- return changeAction ( model , getValue ( value ) , {
237
- currentValue : modelValue ,
238
- external : false ,
239
- } ) ;
211
+ return this . props . changeAction (
212
+ this . props . model ,
213
+ this . getValue ( event ) , {
214
+ currentValue : this . props . modelValue ,
215
+ external : false ,
216
+ } ) ;
240
217
}
241
218
242
219
getValidateAction ( value , eventName ) {
@@ -361,6 +338,10 @@ function createControlClass(s = defaultStrategy) {
361
338
}
362
339
}
363
340
341
+ getValue ( event ) {
342
+ return this . props . getValue ( event , this . props ) ;
343
+ }
344
+
364
345
isToggle ( ) {
365
346
const { component, controlProps } = this . props ;
366
347
@@ -426,11 +407,9 @@ function createControlClass(s = defaultStrategy) {
426
407
}
427
408
428
409
handleChange ( event ) {
429
- const { getValue } = this . props ;
430
-
431
410
if ( event && event . persist ) event . persist ( ) ;
432
411
433
- this . setViewValue ( getValue ( event ) ) ;
412
+ this . setViewValue ( this . getValue ( event ) ) ;
434
413
this . handleUpdate ( event ) ;
435
414
}
436
415
@@ -504,7 +483,6 @@ function createControlClass(s = defaultStrategy) {
504
483
ignore,
505
484
withField,
506
485
fieldValue,
507
- getValue,
508
486
} = this . props ;
509
487
510
488
const eventAction = {
@@ -557,7 +535,7 @@ function createControlClass(s = defaultStrategy) {
557
535
} ,
558
536
dispatchBatchActions ,
559
537
parser ,
560
- getValue ,
538
+ ( e ) => this . getValue ( e ) ,
561
539
persistEventWithCallback ( controlEventHandler || identity )
562
540
) ( event , withField ? fieldValue : undefined ) ;
563
541
} ;
@@ -740,6 +718,7 @@ function createControlClass(s = defaultStrategy) {
740
718
...controlPropsMap . checkbox ,
741
719
...props . mapProps ,
742
720
} }
721
+ getValue = { getCheckboxValue }
743
722
changeAction = { props . changeAction || s . actions . checkWithValue }
744
723
{ ...omit ( props , 'mapProps' ) }
745
724
/>
0 commit comments