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

Commit 675f322

Browse files
committed
Linting
1 parent f0e6f18 commit 675f322

File tree

1 file changed

+40
-28
lines changed

1 file changed

+40
-28
lines changed

src/components/form-component.js

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable */
1+
22
// TODO: Fix all eslint issues
33
import React, { Component, PropTypes } from 'react';
44
import connect from 'react-redux/lib/components/connect';
@@ -10,73 +10,85 @@ import actions from '../actions';
1010
import { validate, isValid } from '../utils';
1111

1212
class Form extends Component {
13-
handleSubmit(e) {
14-
e.preventDefault();
13+
constructor(props) {
14+
super(props);
1515

16+
this.handleSubmit = this.handleSubmit.bind(this);
17+
}
18+
componentDidUpdate(prevProps) {
19+
/* eslint-disable react/prop-types */
1620
const {
17-
model,
1821
validators,
19-
onSubmit,
20-
dispatch
22+
model,
23+
dispatch,
24+
validateOn,
2125
} = this.props;
22-
const modelValue = _get(this.props, model);
26+
/* eslint-enable react/prop-types */
2327

24-
const valid = isValid(mapValues(validators, (validator, field) => {
28+
if (validateOn !== 'change') return;
29+
30+
mapValues(validators, (validator, field) => {
2531
const fieldModel = [model, field].join('.');
2632
const value = _get(this.props, fieldModel);
27-
const validity = validate(validator, value);
2833

29-
dispatch(actions.setValidity(fieldModel, validate(validator, value)));
34+
if (value === _get(prevProps, fieldModel)) return;
3035

31-
return isValid(validity);
32-
}));
36+
const validity = validate(validator, value);
3337

34-
if (onSubmit && !!valid) {
35-
onSubmit(modelValue);
36-
}
38+
dispatch(actions.setValidity(fieldModel, validity));
39+
});
3740
}
3841

39-
componentDidUpdate(prevProps) {
42+
handleSubmit(e) {
43+
e.preventDefault();
44+
45+
/* eslint-disable react/prop-types */
4046
const {
41-
validators,
4247
model,
43-
modelValue,
48+
validators,
49+
onSubmit,
4450
dispatch,
45-
validateOn
4651
} = this.props;
52+
/* eslint-enable react/prop-types */
4753

48-
if (validateOn !== 'change') return;
54+
const modelValue = _get(this.props, model);
4955

50-
mapValues(validators, (validator, field) => {
56+
const valid = isValid(mapValues(validators, (validator, field) => {
5157
const fieldModel = [model, field].join('.');
5258
const value = _get(this.props, fieldModel);
53-
54-
if (value === _get(prevProps, fieldModel)) return;
55-
5659
const validity = validate(validator, value);
5760

5861
dispatch(actions.setValidity(fieldModel, validate(validator, value)));
59-
});
62+
63+
return isValid(validity);
64+
}));
65+
66+
if (onSubmit && !!valid) {
67+
onSubmit(modelValue);
68+
}
6069
}
6170

6271
render() {
72+
/* eslint-disable react/prop-types */
6373
return (
6474
<form
6575
{...this.props}
66-
onSubmit={(e) => this.handleSubmit(e)}
76+
onSubmit={this.handleSubmit}
6777
>
6878
{ this.props.children }
6979
</form>
7080
);
81+
/* eslint-enable react/prop-types */
7182
}
7283
}
7384

74-
Form.PropTypes = {
85+
Form.propTypes = {
7586
validators: PropTypes.object,
7687
validateOn: PropTypes.oneOf([
7788
'change',
7889
]),
79-
model: PropTypes.string.isRequired
90+
model: PropTypes.string.isRequired,
91+
onSubmit: PropTypes.func,
8092
};
8193

8294
export default connect(identity)(Form);

0 commit comments

Comments
 (0)