Skip to content
This repository was archived by the owner on Nov 26, 2021. It is now read-only.

Commit c66d675

Browse files
committed
change contextTypes to formControl.
1 parent 1adf39b commit c66d675

File tree

10 files changed

+53
-68
lines changed

10 files changed

+53
-68
lines changed

lib/Field.js

Lines changed: 11 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Field.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/FormControl.js

Lines changed: 2 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/FormControl.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Message.js

Lines changed: 11 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Message.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-validate-framework",
3-
"version": "0.12.1",
3+
"version": "0.13.0",
44
"description": "React validation framework.",
55
"main": "lib/index.js",
66
"scripts": {

src/Field.jsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,28 @@ import PropTypes from 'prop-types';
44
/**
55
* Field component
66
* @param FormComponent
7-
* @param fieldType
7+
* @param fieldType - Input type
88
* @param name
9-
* @param props
10-
* @param fields
11-
* @param initField
12-
* @param onFormChange
9+
* @param props - Other params
10+
* @param fields - ContextType
11+
* @param init - ContextType
12+
* @param onFormChange - ContextType
1313
* @constructor
1414
*/
1515
const Field = (FormComponent, fieldType, {
1616
name,
1717
...props
1818
}, {
19-
fields,
20-
initField,
21-
onFormChange,
19+
formControl: {
20+
fields,
21+
init,
22+
onFormChange,
23+
},
2224
}) => {
2325
// Initialize field.
2426
if (!fields[name]) {
2527
// Checkbox uses an array
26-
initField({
28+
init({
2729
[name]: fieldType === 'checkbox' ? [] : '',
2830
});
2931
}
@@ -42,9 +44,7 @@ Field.propTypes = {
4244
};
4345

4446
Field.contextTypes = {
45-
fields: PropTypes.object.isRequired,
46-
initField: PropTypes.func.isRequired,
47-
onFormChange: PropTypes.func.isRequired,
47+
formControl: PropTypes.object.isRequired,
4848
};
4949

5050
export default Field;

src/FormControl.jsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ export default (schemas, methods) => FormComponent => (
2828
};
2929

3030
static childContextTypes = {
31-
fields: PropTypes.object.isRequired,
32-
initField: PropTypes.func.isRequired,
33-
onFormChange: PropTypes.func.isRequired,
31+
formControl: PropTypes.object.isRequired,
3432
};
3533

3634
static defaultProps = {
@@ -76,9 +74,7 @@ export default (schemas, methods) => FormComponent => (
7674

7775
getChildContext() {
7876
return {
79-
fields: this.state.fields,
80-
initField: this.init,
81-
onFormChange: this.onFormChange,
77+
formControl: this,
8278
};
8379
}
8480

src/Message.jsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33

4-
const propTypes = {
5-
name: PropTypes.string.isRequired,
6-
htmlFor: PropTypes.string,
7-
};
8-
9-
const contextTypes = {
10-
fields: PropTypes.object.isRequired,
11-
};
12-
134
/**
145
* Error message component
156
* @param name
167
* @param htmlFor
17-
* @param props
18-
* @param fields
8+
* @param props - Other params
9+
* @param fields - ContextType
1910
* @constructor
2011
*/
21-
const Message = ({ name, htmlFor, ...props }, { fields }) => (
12+
const Message = ({ name, htmlFor, ...props }, { formControl: { fields } }) => (
2213
<label
2314
htmlFor={htmlFor}
2415
{...props}
@@ -27,7 +18,13 @@ const Message = ({ name, htmlFor, ...props }, { fields }) => (
2718
</label>
2819
);
2920

30-
Message.propTypes = propTypes;
31-
Message.contextTypes = contextTypes;
21+
Message.propTypes = {
22+
name: PropTypes.string.isRequired,
23+
htmlFor: PropTypes.string,
24+
};
25+
26+
Message.contextTypes = {
27+
formControl: PropTypes.object.isRequired,
28+
};
3229

3330
export default Message;

0 commit comments

Comments
 (0)