Skip to content

Commit edac336

Browse files
committed
Modified examples/demos/demo1.js
Modified package.json Modified src/Form.js Modified src/FormItem.js Add src/index.d.ts
1 parent ca6c449 commit edac336

File tree

5 files changed

+222
-134
lines changed

5 files changed

+222
-134
lines changed

examples/demos/demo1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ export default class DEMO extends Component {
9999
onSubmit={this.onSubmit}
100100
validators={this.getRules()}
101101
renderFieldExtra={this.renderFieldExtra}
102-
inline
103102
validateTrigger="blur"
103+
inline
104104
>
105105
{form => {
106106
return (

package.json

Lines changed: 121 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,123 @@
11
{
2-
"name": "react-widget-form",
3-
"version": "0.2.0",
4-
"description": "",
5-
"main": "index.js",
6-
"dependencies": {
7-
"@babel/runtime": "^7.6.3",
8-
"@babel/runtime-corejs2": "^7.6.3",
9-
"async-validator": "^1.12.2",
10-
"bplokjs-dom-utils": "^1.0.8",
11-
"classnames": "^2.2.6",
12-
"lodash": "^4.17.15",
13-
"object.omit": "^3.0.0",
14-
"omit.js": "^1.0.2",
15-
"prop-types": "^15.6.2",
16-
"react": "^16.11.0",
17-
"react-dom": "^16.11.0",
18-
"react-widget-base-css": "^0.1.0",
19-
"react-widget-icon": "^0.2.0",
20-
"react-widget-input": "^0.2.0",
21-
"warning": "^4.0.2"
22-
},
23-
"devDependencies": {
24-
"@babel/core": "^7.6.4",
25-
"@babel/plugin-proposal-async-generator-functions": "^7.1.0",
26-
"@babel/plugin-proposal-class-properties": "^7.5.5",
27-
"@babel/plugin-proposal-decorators": "^7.6.0",
28-
"@babel/plugin-proposal-do-expressions": "^7.6.0",
29-
"@babel/plugin-proposal-export-default-from": "^7.5.2",
30-
"@babel/plugin-proposal-export-namespace-from": "^7.5.2",
31-
"@babel/plugin-proposal-function-bind": "^7.0.0",
32-
"@babel/plugin-proposal-function-sent": "^7.5.0",
33-
"@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
34-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4",
35-
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
36-
"@babel/plugin-proposal-optional-chaining": "^7.6.0",
37-
"@babel/plugin-proposal-pipeline-operator": "^7.5.0",
38-
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
39-
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
40-
"@babel/plugin-transform-flow-strip-types": "^7.6.3",
41-
"@babel/plugin-transform-modules-amd": "^7.5.0",
42-
"@babel/plugin-transform-modules-commonjs": "^7.6.0",
43-
"@babel/plugin-transform-modules-systemjs": "^7.5.0",
44-
"@babel/plugin-transform-modules-umd": "^7.1.0",
45-
"@babel/plugin-transform-proto-to-assign": "^7.5.5",
46-
"@babel/plugin-transform-react-jsx": "^7.0.0",
47-
"@babel/plugin-transform-react-jsx-self": "^7.0.0",
48-
"@babel/plugin-transform-runtime": "^7.6.2",
49-
"@babel/preset-env": "^7.6.3",
50-
"@babel/preset-flow": "^7.0.0",
51-
"@babel/preset-react": "^7.6.3",
52-
"autoprefixer": "^9.6.5",
53-
"babel-eslint": "^10.0.3",
54-
"babel-loader": "^8.0.6",
55-
"babel-preset-packez": "^0.4.2",
56-
"bplokjs-deferred": "^1.0.0",
57-
"chalk": "^2.4.1",
58-
"clean-webpack-plugin": "^0.1.19",
59-
"core-js": "^3.3.3",
60-
"css-loader": "^1.0.0",
61-
"eslint": "^6.5.1",
62-
"eslint-config-packez": "^0.3.0",
63-
"eslint-loader": "^3.0.2",
64-
"extract-loader": "^3.0.0",
65-
"file-loader": "^2.0.0",
66-
"html-loader": "^0.5.5",
67-
"html-webpack-plugin": "^3.2.0",
68-
"jquery": "^3.4.1",
69-
"json5-loader": "^1.0.1",
70-
"make-webpack-config": "^1.5.2",
71-
"mini-css-extract-plugin": "^0.4.3",
72-
"node-sass": "^4.12.0",
73-
"opn": "^5.5.0",
74-
"optimize-css-assets-webpack-plugin": "^5.0.3",
75-
"packez": "^2.3.1",
76-
"postcss": "^7.0.18",
77-
"postcss-flexbugs-fixes": "^4.1.0",
78-
"postcss-loader": "^3.0.0",
79-
"postcss-preset-env": "^6.7.0",
80-
"postcss-safe-parser": "^4.0.1",
81-
"precss": "^3.1.2",
82-
"raw-loader": "^0.5.1",
83-
"sass-loader": "^7.3.1",
84-
"simple-tree-store": "^1.1.2",
85-
"style-loader": "^1.0.0",
86-
"transform-es": "^3.2.1",
87-
"url-loader": "^1.1.1",
88-
"webpack": "^4.41.2",
89-
"webpack-dev-server": "^3.9.0",
90-
"webpack-manifest-plugin": "^2.2.0",
91-
"webpack-merge": "^4.2.2"
92-
},
93-
"files": [
94-
"*.js",
95-
"lib",
96-
"*.md"
97-
],
98-
"scripts": {
99-
"docs": "packez build ./examples/index.js -d docs -w -c",
100-
"start": "transform-es src -d lib -c -w --corejs false",
101-
"demo": "packez server ./examples/index.js -d dist -w -c",
102-
"test": "echo \"Error: no test specified\" && exit 1",
103-
"build": "packez build ./src/index.js -c",
104-
"server": "packez server ./src/index.js -c",
105-
"analyzer": "packez analyzer ./src/index.js -c"
106-
},
107-
"repository": {
108-
"type": "git",
109-
"url": "git+https://github.com/react-widget/form.git"
110-
},
111-
"keywords": [
112-
"react-widget",
113-
"form",
114-
"react"
115-
],
116-
"author": "nobo.zhou@foxmail.com",
117-
"license": "MIT",
118-
"bugs": {
119-
"url": "https://github.com/react-widget/form/issues"
120-
},
121-
"homepage": "https://github.com/react-widget/form#readme",
122-
"browserslist": [
123-
">1%",
124-
"not dead",
125-
"not ie <= 11",
126-
"not op_mini all"
127-
]
2+
"name": "react-widget-form",
3+
"version": "0.2.0",
4+
"description": "",
5+
"main": "index.js",
6+
"dependencies": {
7+
"@babel/runtime": "^7.6.3",
8+
"classnames": "^2.2.6",
9+
"lodash": "^4.17.15",
10+
"prop-types": "^15.6.2",
11+
"react": "^16.11.0",
12+
"react-dom": "^16.11.0",
13+
"warning": "^4.0.2"
14+
},
15+
"devDependencies": {
16+
"@babel/core": "^7.6.4",
17+
"@babel/plugin-proposal-async-generator-functions": "^7.1.0",
18+
"@babel/plugin-proposal-class-properties": "^7.5.5",
19+
"@babel/plugin-proposal-decorators": "^7.6.0",
20+
"@babel/plugin-proposal-do-expressions": "^7.6.0",
21+
"@babel/plugin-proposal-export-default-from": "^7.5.2",
22+
"@babel/plugin-proposal-export-namespace-from": "^7.5.2",
23+
"@babel/plugin-proposal-function-bind": "^7.0.0",
24+
"@babel/plugin-proposal-function-sent": "^7.5.0",
25+
"@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
26+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4",
27+
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
28+
"@babel/plugin-proposal-optional-chaining": "^7.6.0",
29+
"@babel/plugin-proposal-pipeline-operator": "^7.5.0",
30+
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
31+
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
32+
"@babel/plugin-transform-flow-strip-types": "^7.6.3",
33+
"@babel/plugin-transform-modules-amd": "^7.5.0",
34+
"@babel/plugin-transform-modules-commonjs": "^7.6.0",
35+
"@babel/plugin-transform-modules-systemjs": "^7.5.0",
36+
"@babel/plugin-transform-modules-umd": "^7.1.0",
37+
"@babel/plugin-transform-proto-to-assign": "^7.5.5",
38+
"@babel/plugin-transform-react-jsx": "^7.0.0",
39+
"@babel/plugin-transform-react-jsx-self": "^7.0.0",
40+
"@babel/plugin-transform-runtime": "^7.6.2",
41+
"@babel/preset-env": "^7.6.3",
42+
"@babel/preset-flow": "^7.0.0",
43+
"@babel/preset-react": "^7.6.3",
44+
"autoprefixer": "^9.6.5",
45+
"babel-eslint": "^10.0.3",
46+
"babel-loader": "^8.0.6",
47+
"babel-preset-packez": "^0.4.2",
48+
"bplokjs-deferred": "^1.0.0",
49+
"chalk": "^2.4.1",
50+
"clean-webpack-plugin": "^0.1.19",
51+
"core-js": "^3.3.3",
52+
"css-loader": "^1.0.0",
53+
"eslint": "^6.5.1",
54+
"eslint-config-packez": "^0.3.0",
55+
"eslint-loader": "^3.0.2",
56+
"extract-loader": "^3.0.0",
57+
"file-loader": "^2.0.0",
58+
"html-loader": "^0.5.5",
59+
"html-webpack-plugin": "^3.2.0",
60+
"jquery": "^3.4.1",
61+
"json5-loader": "^1.0.1",
62+
"make-webpack-config": "^1.5.2",
63+
"mini-css-extract-plugin": "^0.4.3",
64+
"node-sass": "^4.12.0",
65+
"opn": "^5.5.0",
66+
"optimize-css-assets-webpack-plugin": "^5.0.3",
67+
"packez": "^2.3.1",
68+
"postcss": "^7.0.18",
69+
"postcss-flexbugs-fixes": "^4.1.0",
70+
"postcss-loader": "^3.0.0",
71+
"postcss-preset-env": "^6.7.0",
72+
"postcss-safe-parser": "^4.0.1",
73+
"precss": "^3.1.2",
74+
"raw-loader": "^0.5.1",
75+
"sass-loader": "^7.3.1",
76+
"simple-tree-store": "^1.1.2",
77+
"style-loader": "^1.0.0",
78+
"transform-es": "^3.2.1",
79+
"url-loader": "^1.1.1",
80+
"webpack": "^4.41.2",
81+
"webpack-dev-server": "^3.9.0",
82+
"webpack-manifest-plugin": "^2.2.0",
83+
"webpack-merge": "^4.2.2",
84+
"react-widget-base-css": "^0.1.0",
85+
"react-widget-icon": "^0.2.0",
86+
"react-widget-input": "^0.2.0"
87+
},
88+
"files": [
89+
"*.js",
90+
"lib",
91+
"*.md"
92+
],
93+
"scripts": {
94+
"docs": "packez build ./examples/index.js -d docs -w -c",
95+
"start": "transform-es src -d lib -c -w --corejs false",
96+
"demo": "packez server ./examples/index.js -d dist -w -c",
97+
"test": "echo \"Error: no test specified\" && exit 1",
98+
"build": "packez build ./src/index.js -c",
99+
"server": "packez server ./src/index.js -c",
100+
"analyzer": "packez analyzer ./src/index.js -c"
101+
},
102+
"repository": {
103+
"type": "git",
104+
"url": "git+https://github.com/react-widget/form.git"
105+
},
106+
"keywords": [
107+
"react-widget",
108+
"form",
109+
"react"
110+
],
111+
"author": "nobo.zhou@foxmail.com",
112+
"license": "MIT",
113+
"bugs": {
114+
"url": "https://github.com/react-widget/form/issues"
115+
},
116+
"homepage": "https://github.com/react-widget/form#readme",
117+
"browserslist": [
118+
">1%",
119+
"not dead",
120+
"not ie <= 11",
121+
"not op_mini all"
122+
]
128123
}

src/Form.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import React from "react";
22
import PropTypes from "prop-types";
33
import classnames from "classnames";
4-
import AsyncValidator from "async-validator";
54
import set from "lodash/set";
65
import get from "lodash/get";
76
import FormContext from "./FormContext";
87
import { isEmptyValue, deferred } from "./utils";
98

109
function noop() {}
1110

12-
AsyncValidator.warning = noop;
13-
1411
export default class Form extends React.Component {
1512
static propTypes = {
1613
prefixCls: PropTypes.string,
@@ -34,7 +31,6 @@ export default class Form extends React.Component {
3431
inline: PropTypes.bool,
3532
onSubmit: PropTypes.func,
3633
onChange: PropTypes.func,
37-
validateFieldsAndScroll: PropTypes.bool,
3834
getInputProps: PropTypes.func
3935
};
4036

@@ -186,7 +182,7 @@ export default class Form extends React.Component {
186182
hasError(name) {
187183
const { formError } = this.state;
188184

189-
return formError[name] !== null;
185+
return formError[name] != null; // null or undefined
190186
}
191187

192188
getError(name) {
@@ -196,6 +192,11 @@ export default class Form extends React.Component {
196192

197193
cleanError(name) {
198194
const { formError } = this.state;
195+
196+
if (!this.hasError(name)) {
197+
return;
198+
}
199+
199200
this.setState({
200201
formError: {
201202
...formError,
@@ -274,7 +275,7 @@ export default class Form extends React.Component {
274275

275276
_validateField(name, callback) {
276277
callback = typeof callback === "function" ? callback : noop;
277-
278+
const { formValue } = this.state;
278279
const value = this.getValue(name);
279280
const validators = this.getFieldValidator(name);
280281

@@ -319,7 +320,7 @@ export default class Form extends React.Component {
319320
return; //check finish
320321
}
321322

322-
const ret = validator(value);
323+
const ret = validator(value, formValue);
323324
if (ret === true) {
324325
cb();
325326
} else if (ret === false) {

src/FormItem.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default class FormItem extends React.Component {
1919
alignItems: PropTypes.oneOf(["top", "center", "bottom"]),
2020
validator: PropTypes.oneOfType([PropTypes.func, PropTypes.array]),
2121
required: PropTypes.bool,
22+
requiredMessage: PropTypes.string,
2223
clearErrorOnFocus: PropTypes.bool,
2324
normalize: PropTypes.func,
2425
renderExtra: PropTypes.func,

0 commit comments

Comments
 (0)