Skip to content
This repository was archived by the owner on Aug 23, 2022. It is now read-only.

Commit f20c5e4

Browse files
committed
Fixing lint errors
1 parent d784058 commit f20c5e4

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/components/field-component.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { Component, PropTypes } from 'react';
22
import shallowCompare from 'react/lib/shallowCompare';
33
import connect from 'react-redux/lib/components/connect';
4+
import icepick from 'icepick';
45

56
import _get from '../utils/get';
67
import identity from 'lodash/identity';
@@ -36,12 +37,30 @@ function isChecked(props) {
3637
return !!props.modelValue;
3738
}
3839

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+
3957
const controlPropsMap = {
4058
default: (props) => controlPropsMap.text(props),
4159
checkbox: (props) => ({
4260
...props,
4361
name: props.model,
4462
checked: isChecked(props),
63+
updater: checkboxChanger,
4564
}),
4665
radio: (props) => ({
4766
...props,
@@ -114,9 +133,7 @@ function createFieldControlComponent(control, props, options) {
114133
}
115134

116135
/* eslint-disable react/prop-types */
117-
const {
118-
mapProps = options.controlPropsMap[getControlType(control, options)],
119-
} = props;
136+
const mapProps = options.controlPropsMap[getControlType(control, options)];
120137

121138
const controlProps = omit(props, ['children', 'className']);
122139

@@ -196,6 +213,11 @@ function createFieldClass(customControlPropsMap = {}, defaultProps = {}) {
196213
]),
197214
parser: PropTypes.func,
198215
formatter: PropTypes.func,
216+
formatOn: PropTypes.oneOf([
217+
'change',
218+
'blur',
219+
'focus',
220+
]),
199221
updateOn: PropTypes.oneOf([
200222
'change',
201223
'blur',
@@ -213,14 +235,14 @@ function createFieldClass(customControlPropsMap = {}, defaultProps = {}) {
213235
PropTypes.func,
214236
PropTypes.object,
215237
]),
216-
mapProps: PropTypes.func,
217238
modelValue: PropTypes.any,
218239
};
219240

220241
Field.defaultProps = {
221242
updateOn: 'change',
222243
validateOn: 'change',
223244
asyncValidateOn: 'blur',
245+
formatOn: 'blur',
224246
parser: identity,
225247
formatter: identity,
226248
changeAction: change,

test/field-component-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ describe('<Field /> component', () => {
15351535
<Provider store={store}>
15361536
<Field
15371537
model="test.foo"
1538-
formatter={(val) => val + '!!!'}
1538+
formatter={(val) => `${val}!!!`}
15391539
>
15401540
<input />
15411541
</Field>

0 commit comments

Comments
 (0)