Skip to content

Commit 751385d

Browse files
committed
fix validate bug
1 parent 4ff08eb commit 751385d

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

jest/Form.test.tsx

+21
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,25 @@ test('Form getFieldProps Test', () => {
1818
const field = formInstance.getFieldProps('test');
1919
expect(field).toEqual(input);
2020

21+
});
22+
23+
24+
25+
test('Form validate Test', () => {
26+
const formInstance = new FormInstance();
27+
28+
const input = {
29+
type: 'input',
30+
props: {
31+
name: 'test',
32+
label: 'test',
33+
}
34+
} as FormField;
35+
36+
formInstance.resetFields([input]);
37+
38+
formInstance.validate().then(result=>{
39+
expect(result).toEqual(true);
40+
});
41+
2142
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codingapi/ui-framework",
3-
"version": "0.0.12",
3+
"version": "0.0.13",
44
"description": "A UI Framework built with React and Typescript",
55
"keywords": [
66
"ui",

src/Form/validate.ts

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ export class FormValidateContext {
8080
}
8181

8282
public validate = async (form: FormInstance) => {
83+
if (this.map.size <= 0) {
84+
return Promise.resolve(true);
85+
}
8386
const list = Array.from(this.map.keys().map(item => {
8487
return this.validateField(item, form);
8588
}));

0 commit comments

Comments
 (0)